PHP array_diff_key() Function
The array_diff_key() function is used to compare the keys from an array against the keys from another array and returns the difference. This function is like array_diff() except the comparison is done on the keys instead of the values.
An array containing all the entries from array1 whose keys are not present in any of the other arrays i.e. array2, array3 etc..
Parameter | Description |
---|---|
array1 | Required. The array to compare from |
array2 | Required. An array to compare against |
array3,… | Optional. More arrays to compare against |
Syntax
array_diff_key(array1,array2,array3...);
Example
$array1=array("a"=>"Prince","b"=>"James","c"=>"Samuel","d"=>"Cooper");
$array2=array("a"=>"Prince","b"=>"James","c"=>"Samuel");
$result=array_diff_key($array1,$array2);
print_r($result);
Output
Array ( [d] => Cooper )
Leave a Reply