$array= array(
Array(
"4187~2" => Array (
"providerId" => 2,
"pFEP" => 80,
),
"4187~1" => Array (
"providerId" => 1,
"pFEP" => 10,
),
),
Array(
"4187~2" => Array (
"providerId" => 2,
"pFEP" => 80,
),
"4187~1" => Array (
"providerId" => 1,
"pFEP" => 10,
),
),
Array(
"4187~2"=> Array
(
"providerId" => 2,
"pFEP" => 80,
),
"4187~1" => Array (
"providerId" => 1,
"pFEP" => 10,
),
"5046~2" => Array (
"providerId" => 2,
"pFEP" => 15
),
));
Требуется вывод:
$output = array(
Array(
"4187~2" => Array
(
"providerId" => 2,
"pFEP" => 80,
),
"4187~1" => Array
(
"providerId" => 1,
"pFEP" => 10,
),
"5046~2" => Array
(
"providerId" => 2,
"pFEP" => 15
),
));
Я попробовал следующую функцию от Google. Это не дает требуемого вывода:
function array_unique_key($input, &$keys = []) {
$input = array_filter($input, function($key) use (&$keys) {
return isset($keys[$key]) ? false: $keys[$key] = true;
}, ARRAY_FILTER_USE_KEY);
return array_map(function($value) use (&$keys) {
return is_array($value) ? array_unique_key($value, $keys): $value;
}, $input);
}
print_r(array_unique_key($array));