note 102596 added to function.array-diff
[email protected] Wed, 23 Feb 2011 10:23:29 -0800
| Newsgroups | php.notes |
|---|---|
| Message-ID | <[email protected]> |
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
)
----
Server IP: 194.50.97.14
Probable Submitter: 94.227.67.171
----
Manual Page -- http://www.php.net/manual/en/function.array-diff.php
Edit -- https://master.php.net/note/edit/102596
Del: integrated -- https://master.php.net/note/delete/102596/integrated
Del: useless -- https://master.php.net/note/delete/102596/useless
Del: bad code -- https://master.php.net/note/delete/102596/bad+code
Del: spam -- https://master.php.net/note/delete/102596/spam
Del: non-english -- https://master.php.net/note/delete/102596/non-english
Del: in docs -- https://master.php.net/note/delete/102596/in+docs
Del: other reasons-- https://master.php.net/note/delete/102596
Reject -- https://master.php.net/note/reject/102596
Search -- https://master.php.net/manage/user-notes.php