Voting

: min(zero, nine)?
(Example: nine)

The Note You're Voting On

michiel at synetic dot nl
15 years ago
A small improvement upon the previously posted array_merge_recursive_distinct functions (based on daniel's version). This implementation preserves the parameter input from the original, you can pass an infinite amount of array's to merge.

<?php
function &array_merge_recursive_distinct()
{
$aArrays = func_get_args();
$aMerged = $aArrays[0];

for(
$i = 1; $i < count($aArrays); $i++)
{
if (
is_array($aArrays[$i]))
{
foreach (
$aArrays[$i] as $key => $val)
{
if (
is_array($aArrays[$i][$key]))
{
$aMerged[$key] = is_array($aMerged[$key]) ? PR::array_merge_recursive_distinct($aMerged[$key], $aArrays[$i][$key]) : $aArrays[$i][$key];
}
else
{
$aMerged[$key] = $val;
}
}
}
}

return
$aMerged;
}
?>

<< Back to user notes page

To Top