note 113725 added to function.array-intersect
| From: | juliotorres1604 at hotmail dot com | Date: | Thu, 21 Nov 2013 14:34:21 +0000 |
| Subject: | note 113725 added to function.array-intersect | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-197606@lists.php.net to get a copy of this message | ||
<?php
// Function to intersect n arrays
function getIntersect($arrays){
$totalArrays = count($arrays);
if($totalArrays >= 2){
$arrayTmp = $arrays[0];
for ($i = 1; $i < $totalArrays; $i++) {
$arrayTmp = array_intersect($arrayTmp, $arrays[$i]);
}
return $arrayTmp;
}else{
return FALSE;
}
}
// Example:
$arrayTmp[0] = array('0'=>0, '1'=>7, '2'=>5);
$arrayTmp[1] = array('0'=>7, '1'=>5, '2'=>0,
'3'=>15);
$arrayTmp[2] = array('0'=>3, '1'=>0, '2'=>7,
'3'=>4);
$intersectArray = getIntersect($arrayTmp);
print_r($arrayFinal);
?>
The above example will output:
Array
(
[0] => 0
[1] => 7
)
----
Server IP: 72.52.91.14
Probable Submitter: 72.52.91.14
----
Manual Page -- http://php.net/manual/en/function.array-intersect.php
Edit -- https://master.php.net/note/edit/113725
Del: integrated -- https://master.php.net/note/delete/113725/integrated
Del: useless -- https://master.php.net/note/delete/113725/useless
Del: bad code -- https://master.php.net/note/delete/113725/bad+code
Del: spam -- https://master.php.net/note/delete/113725/spam
Del: non-english -- https://master.php.net/note/delete/113725/non-english
Del: in docs -- https://master.php.net/note/delete/113725/in+docs
Del: other reasons-- https://master.php.net/note/delete/113725
Reject -- https://master.php.net/note/reject/113725
Search -- https://master.php.net/manage/user-notes.php