- reset: documentation ( source)
- print_r: documentation ( source)
- array_shift: documentation ( source)
<?php
abstract class wtf {
function array_merge_recursive_distinct() {
$arrays = func_get_args();
$base = array_shift($arrays);
foreach ($arrays as $array) {
reset($base); //important
while (list($key, $value) = @each($array)) {
if (is_array($value) && @is_array($base[$key])) {
$base[$key] = self::array_merge_recursive_distinct($base[$key], $value);
} else {
$base[$key] = $value;
}
}
}
return $base;
}
}
$a = array(
"exists" => 1,
"doesnotexist" => 1,
"arraytest" => array(
"exists" => 1,
"doesnotexist" => 1
)
);
$b = array(
"exists" => 2,
"arraytest" => array(
"exists" => 2,
)
);
$c = wtf::array_merge_recursive_distinct($a, $b);
print_r($c);