note 113725 deleted from function.array-intersect by cmb
| From: | cmb@php.net | Date: | Sun, 15 Dec 2019 10:33:41 +0000 |
| Subject: | note 113725 deleted from function.array-intersect by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-213539@lists.php.net to get a copy of this message | ||
Note Submitter: juliotorres1604 at hotmail dot com
----
<?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
)