array_diff_key() function calculates the difference set of an array using key name comparison
【Function】
This function will return an array,
This array contains the values of all keys that are in array1 but are not in any other parameter array.
【Scope of use】
>=5.1.0
【Use】
array array_diff_key( array array1, array array2[,array...] )
array1/required/array1
array2/required/comparable array must have at least one
array.../optional/array used for comparison
【Example】
[php]
$arr1 = array( "key1" => "val1", "key2" => "val2" );
$arr2 = array( "key1" => "val1", "key3" => "val2" );
$arr3 = array( "key2" => "val2" );
print_r( array_diff_key( $arr1, $arr2 ) );
print_r( array_diff_key( $arr1, $arr3 ) );
print_r( array_diff_key( $arr1, $arr2, $arr3 ) );
/*
Array
(
[key2] => val2
)
Array
(
[key1] => val1
)
Array
(
)
*/
Excerpted from zuodefeng’s notes