Definition and usage
The Array_diff_key () function returns an array that contains all the keys in the array being compared, but not in any other parameter array.
Grammar
Array_diff_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. |
Hints and Notes
Tip: You can use one or any number of arrays to compare to the first array.
Note: Only key names are used for comparisons.
Example
<?php$a1=array (0=> "Cat",1=> "Dog",2=> "Horse"), $a 2=array (2=> "Bird",3=> "Rat",4=> "Fish"); $a 3 = Array (5=> "Horse",6=> "Dog",7=> "Bird");p Rint_r (Array_diff_key ($a 1, $a 2, $a 3)); >
Output:
Array ([0] = Cat [1] = Dog)
PHP Array_diff_key ()