Voting

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

The Note You're Voting On

miniscalope at gmail dot com
16 years ago
I would merge 2 arrays but keep the values unique in the result array.
I hope this will help...
<?php

function array_merge_recursive_unique($array1, $array2) {

foreach(
$array2 AS $k => $v) {
if(!isset(
$array1[$k]))
{
$array1[$k] = $v;
}
else
{
if(!
is_array($v)){
if(
is_array($array1[$k]))
{
if(!
in_array($v,$array1[$k]))
{
$array1[$k][] = $v;
}
}
else
{
if(
$array1[$k] != $v)
$array1[$k] = array($array1[$k], $v);
}
}
else
{
$array1[$k] = array_merge_recursive_unique($array1,$array2[$k]);
}

}

}
unset(
$k, $v);
return
$array1;
}

?>

<< Back to user notes page

To Top