Hello Friends,
If you want to compare two array with respect to keys not values then you can use a predefined PHP function "array_diff_key()". array_diff_key function compares the keys from array1 against the keys from array2 and returns the difference.
Here is a example which will explain this-
<?php
$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4);
$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8);
var_dump(array_diff_key($array1, $array2));
?>
The above example will output:
array(2) {
["red"] => int(2)
["purple"] => int(4)
}
0 Comment(s)