Definitions and usage
The ARRAY_INTERSECT_ASSOC () function returns an array of intersections of two or more arrays.
Unlike the Array_intersect () function, this function compares key values and the key names. The key name of the element in the returned array remains unchanged.
Grammar
Array_intersect_assoc (Array1,array2,array3 ...)
Parameters
Describe
Array1 required. The first array to compare with the other arrays.
Array2 required. The array to compare with the first array.
Array3 Optional. The array to compare with the first array. can have multiple.
Example 1
<?php $a 1=array (0=> "Cat",1=> "Dog",2=> "horse"); $a 2=array (3=> "horse",1=> "Dog",0=> "Cat"); Print_r (ARRAY_INTERSECT_ASSOC ($a 1, $a 2));?>
Output:
Array ([0] => Cat [1] => Dog)
Example 2
<?php $a 1=array (0=> "Cat",1=> "Dog",2=> "horse"); $a 2=array (3=> "horse",1=> "Dog",5=> "Fish"); $a 3=array (6=> "Cow",1=> "Dog",8=> "Fish"); Print_r (ARRAY_INTERSECT_ASSOC ($a 1, $a 2, $a 3));?>
Output:
Array ([1] => Dog)