I have a multidimensional Array I want to delete all duplicate keys, I've tried but not working any script.
Following answer is working for duplicate values and I want same solution for duplicate keys in multidimensional array.
PHP remove duplicate values from multidimensional array
$arr = array(
"a" => "xxx",
"b" => "xxx",
"c" => array(
"g" => "xxx",
"a" => "xxx",
"h" => "xxx",
),
"d" => "xxx",
"e" => array(
"i" => array(
"a" => "xxx",
"k" => array(
"l" => "xxx",
"b" => "xxx",
),
),
"j" => "xxx",
),
"f" => "xxx",
);
I want this result:
$arr = array(
"a" => "xxx",
"b" => "xxx",
"c" => array(
"g" => "xxx",
"h" => "xxx",
),
"d" => "xxx",
"e" => array(
"i" => array(
"k" => array(
"l" => "xxx",
),
),
"j" => "xxx",
),
"f" => "xxx",
);
I'm trying to solve this issue by this function:
function array_unique_key($array) {
$result = array();
foreach (array_unique(array_keys($array)) as $tvalue) {
if (is_array($tvalue)) {
$result[$tvalue] = $array[$tvalue];
}
$result[$tvalue] = $array[$tvalue];
}
return $result;
}