note 86559 modified in function.array-pop by danbrown
| From: | danbrown@php.net | Date: | Thu, 23 Oct 2008 19:15:39 +0000 |
| Subject: | note 86559 modified in function.array-pop by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-145666@lists.php.net to get a copy of this message | ||
I wrote a simple function to perform an intersect on multiple (unlimited) arrays.
Pass an array containing all the arrays you want to compare, along with what key to match by.
<?php
function multipleArrayIntersect($arrayOfArrays, $matchKey)
{
$compareArray = array_pop($arrayOfArrays);
foreach($compareArray AS $key => $valueArray){
foreach($arrayOfArrays AS $subArray => $contents){
if (!in_array($compareArray[$key][$matchKey], $contents)){
unset($compareArray[$key]);
}
}
}
return $compareArray;
}
?>
--was--
I wrote a simple function to perform an intersect on multiple (unlimited) arrays.
Pass an array containing all the arrays you want to compare, along with what key to match by.
function multipleArrayIntersect($arrayOfArrays, $matchKey)
{
$compareArray = array_pop($arrayOfArrays);
foreach($compareArray AS $key => $valueArray){
foreach($arrayOfArrays AS $subArray => $contents){
if (!in_array($compareArray[$key][$matchKey], $contents)){
unset($compareArray[$key]);
}
}
}
return $compareArray;
}
http://php.net/manual/en/function.array-pop.php