This article introduces the method of finding the intersection of associative arrays in PHP arrays. Friends in need can refer to it.
The PHP function array_intersect_assoc() is basically the same as array_intersect(), except that it also considers the keys of the array in the comparison. Therefore, only key/value pairs that appear in the first array and also appear in all other input arrays are returned in the result array. The form is as follows: array array_intersect_assoc(array array1,array array2[,arrayN…]) Example, return all key/value pairs that appear in the $fruit1 array and also appear in $fruit2 and $fruit3: <?php //求关联数组的交集 $fruit1 = array("red"=>"Apple","yellow"=>"Banana","orange"=>"Orange"); $fruit2 = array("yellow"=>"Pear","red"=>"Apple","purple"=>"Grape"); $fruit3 = array("green"=>"Watermelon","orange"=>"Orange","red"=>"Apple"); $intersection = array_intersect_assoc($fruit1, $fruit2, $fruit3); print_r($intersection); //by bbs.it-home.org // output // Array ( [red] => Apple ) ?> Copy after login |