note 102596 deleted from function.array-diff by danbrown
[email protected] Wed, 23 Feb 2011 10:56:15 -0800
| Newsgroups | php.notes |
|---|---|
| Message-ID | <[email protected]> |
Note Submitter: anton
----
Never mind, here's the one i found, slightly based on faharanik's note at the array_intersect. Go ahead and give it a try! I hope this will be usefull for some people.
<?php
function array_uniquevalues($arrays)
{
$argnum = func_num_args();
$args = func_get_args();
$rvalues = array();
foreach($args as $k=>$v)
{
foreach($v as $key=>$value)
{
$occurences = 1;
foreach($args as $kk=>$vv)
{
foreach($vv as $keyy=>$valuee)
{
if($kk != $k)
{
if($value == $valuee)
{
$occurences++;
}
}
}
}
if($occurences == 1)
{
$rvalues[] = $value;
}
}
}
return $rvalues;
}
$array1 = array('red','green','blue');
$array2 = array('red','yellow','green');
$array3 = array('pink','yellow','red');
$array4 = array('black','white','yellow');
$array5 = array('purple','indigo','brown');
print_r(array_uniquevalues($array1,$array2,$array3,$array4,$array5));
?>
RESULT:
Array
(
[0] => blue
[1] => pink
[2] => black
[3] => white
[4] => purple
[5] => indigo
[6] => brown
)