note 102596 deleted from function.array-diff by danbrown

From: Date: Wed, 23 Feb 2011 18:56:15 +0000
Subject: note 102596 deleted from function.array-diff by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-177261@lists.php.net to get a copy of this message
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 )

« previous php.notes (#177261) next »