note 39357 added to function.array-intersect

From: Date: Sun, 25 Jan 2004 22:06:38 +0000
Subject: note 39357 added to function.array-intersect
Groups: php.notes 
Request: Send a blank email to php-notes+get-64174@lists.php.net to get a copy of this message
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 } ?> ---- Manual Page -- http://www.php.net/manual/en/function.array-intersect.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+39357 Delete -- http://master.php.net/manage/user-notes.php?action=delete+39357&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+39357&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#64174) next »