note 39357 deleted from function.array-intersect by tomsommer

From: Date: Sun, 25 Jan 2004 22:24:45 +0000
Subject: note 39357 deleted from function.array-intersect by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-64175@lists.php.net to get a copy of this message
Note Submitter: mchlax at ( verizon) [dot] (net) ---- For something I made, I needed keys not to be maintained. I made my own function, but if there is a quicker way to do this (can I remove keys within an array) please tell me. <?php function array_intersection() { #MChlax $args = func_get_args(); $num = func_num_args(); $count = sizeof($args[0]); $thenum = 0; # Find the smallest array for ($i = 1;$i<$num;$i++) { $cur = sizeof($args[$i]); if ($cur < $count) { $count = sizeof($args[$i]); $thenum = $i; } } #Go through each item in smallest array for ($i=0;$i<$count;$i++) { $isgood = true; $cur = $args[$thenum][$i]; #Go through each array and make sure the current thing #is in there for ($i2=0;$i2<$num;$i2++) { #skip it if the array is the smallest one if ($i2 == $thenum) $i2++; if (!in_array($cur,$args[$i2])) { $isgood = false; break; } #if it matches all of em, add it to the intersect array if ($isgood == true) $intersect[]=$cur; } } return $intersect } ?>

« previous php.notes (#64175) next »