note 102581 deleted from function.array-diff by danbrown

From: Date: Wed, 23 Feb 2011 00:20:58 +0000
Subject: note 102581 deleted from function.array-diff by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-177235@lists.php.net to get a copy of this message
Note Submitter: anton ---- A function to find values that only occur once in a number of arrays. I still need one to allow any amount of input arrays, so if anyone knows, please let me know. This is my function to find all the unique values: <?php function array_uniquevalues($array1,$array2,$array3) { $trvalues[]=array_merge( array_intersect($array1,$array2),array_intersect($array2,$array1) ); $trvalues[]=array_merge( array_intersect($array2,$array3),array_intersect($array3,$array2) ); $trvalues[]=array_merge( array_intersect($array1,$array3),array_intersect($array3,$array1) ); $trvalues=array_unique( array_merge($trvalues[0],$trvalues[1],$trvalues[2]) ); $tvalues=array_unique( array_merge($array1,$array2,$array3) ); $rvalues=array_diff($tvalues,$trvalues); $rvalues=array_values($rvalues); return $rvalues; } $array1 = array('red','green','blue'); $array2 = array('red','yellow','green'); $array3 = array('pink','yellow','red'); print_re(array_uniquevalues($array1,$array2,$array3)); ?> result: Array ( [0]=>blue [1]=>pink )

« previous php.notes (#177235) next »