note 98684 deleted from function.array-intersect by danbrown
| From: | danbrown@php.net | Date: | Wed, 30 Jun 2010 14:31:43 +0000 |
| Subject: | note 98684 deleted from function.array-intersect by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-170604@lists.php.net to get a copy of this message | ||
Note Submitter: faharanik
----
Here's my approach to intersection returning only the values present in all the arrays.
I don't know how effective it actually is, but perhaps it could help.
<?php
// $arrays - Array of arrays to intersect.
function calculate_intersection($arrays)
{
$intersection = Array();
for($checked_item = 0; $checked_item < count($arrays[0]); $checked_item++)
{
$occurence = 1;
for($compared_array = 1; $compared_array < count($arrays); $compared_array++)
{
for($compared_item = 0; $compared_item < count($arrays[$compared_array]); $compared_item++)
{
if($arrays[0][$checked_item] == $arrays[$compared_array][$compared_item])
{
$occurence++;
if($occurence == count($arrays))
{
$intersection[] = $arrays[0][$checked_item];
}
}
}
}
}
return $intersection;
}
?>