note 98684 added to function.array-intersect
| From: | faharanik at osu1 dot php dot net | Date: | Wed, 30 Jun 2010 14:13:53 +0000 |
| Subject: | note 98684 added to function.array-intersect | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-170602@lists.php.net to get a copy of this message | ||
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;
}
?>
----
Server IP: 147.32.160.17
Probable Submitter: 213.192.26.250
----
Manual Page -- http://www.php.net/manual/en/function.array-intersect.php
Edit -- https://master.php.net/note/edit/98684
Del: integrated -- https://master.php.net/note/delete/98684/integrated
Del: useless -- https://master.php.net/note/delete/98684/useless
Del: bad code -- https://master.php.net/note/delete/98684/bad+code
Del: spam -- https://master.php.net/note/delete/98684/spam
Del: non-english -- https://master.php.net/note/delete/98684/non-english
Del: in docs -- https://master.php.net/note/delete/98684/in+docs
Del: other reasons-- https://master.php.net/note/delete/98684
Reject -- https://master.php.net/note/reject/98684
Search -- https://master.php.net/manage/user-notes.php