Definition and usage
The Array_intersect_key () function computes the intersection of an array using the key name comparison.
Array_intersect_key () returns an array that contains all the values of the key names that appear in the array being compared and that appear in all other parameter arrays.
Note: Only key names are used for comparisons.
Grammar
Array_intersect_key (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 (2=> "Bird",0=> "Cat",4=> "Fish"); Print_r (Array_intersect_key ($a 1, $a 2));? >
Output:
Array ([0] = Cat [2] = Horse)
Example 2
<?php$a1 = Array (0=> "Cat",1=> "Dog",2=> "Horse"), $a 2 = Array (2=> "Bird",3=> "Rat",4=> "Fish"); $a 3 = Array (2=> "Dog",6=> "Cow",7=> "Bird");p Rint_r (Array_intersect_key ($a 1, $a 2, $a 3)); >
Output:
Array ([2] = Horse)
PHP Array_intersect_key ()