How to Learn PHP array_intersect_assoc ()
Definition and usage
The array_intersect_assoc () function returns the intersection array of two or more arrays.
Unlike the array_intersect () function, this function compares key names in addition to key values. The key name of the element in the returned array remains unchanged.
Syntax
Array_intersect_assoc (array1, array2, array3 ...)
Parameters
Description
Array1 is required. The first array to be compared with other arrays.
Array2 is required. The array to be compared with the first array.
Array3 is optional. The array to be compared with the first array. There can be multiple.
Example 1
<? Php $ a1 = array (0 => "Cat", 1 => "Dog", 2 => "Horse"); $ a2 = array (3 => "Horse ", 1 => "Dog", 0 => "Cat"); print_r (array_intersect_assoc ($ a1, $ a2);?>
Output:
Array ([0] => Cat [1] => Dog)
Example 2
<? Php $ a1 = array (0 => "Cat", 1 => "Dog", 2 => "Horse"); $ a2 = array (3 => "Horse ", 1 => "Dog", 5 => "Fish"); $ a3 = array (6 => "Cow", 1 => "Dog ", 8 => "Fish"); print_r (array_intersect_assoc ($ a1, $ a2, $ a3);?>
Output:
Array ([1] => Dog)