note 102580 added to function.array-diff

From: Date: Tue, 22 Feb 2011 23:55:49 +0000
Subject: note 102580 added to function.array-diff
Groups: php.notes 
Request: Send a blank email to php-notes+get-177231@lists.php.net to get a copy of this message
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 ) ---- Server IP: 79.99.203.17 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/102580 Del: integrated -- https://master.php.net/note/delete/102580/integrated Del: useless -- https://master.php.net/note/delete/102580/useless Del: bad code -- https://master.php.net/note/delete/102580/bad+code Del: spam -- https://master.php.net/note/delete/102580/spam Del: non-english -- https://master.php.net/note/delete/102580/non-english Del: in docs -- https://master.php.net/note/delete/102580/in+docs Del: other reasons-- https://master.php.net/note/delete/102580 Reject -- https://master.php.net/note/reject/102580 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#177231) next »