Definition 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 names in addition to the key values. The key name of the element in the returned array remains unchanged.
Grammar
Array_intersect_assoc (Array1,array2,array3 ...)
| Parameters |
Describe |
| Array1 |
Necessary. The first array to compare with the other array. |
| Array2 |
Necessary. The array to compare with the first array. |
| Array3 |
Optional. The array to compare with the first array. Can have more than one. |
Example 1
<?php$a1 = 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$a1 = 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");p Rint_r (ARRAY_INTERSECT_ASSOC ($a 1, $a 2, $a 3)); >
Output:
Array ([1] = Dog)
PHP Array_intersect_assoc ()