This function takes two or more arrays as input and then returns the result array as difference.
$new_array = array_diff_key ($array1, $array2,....);
Returns all elements of $array1 which are not present in $array2 ($new_array=$array1 without $array2).... Here comparison is done based on the keys only ( NOT values ).
Comparison of two or more arrays are done by using values in array_diff()
Example with two arrays
$first=array('One' =>'First','Two'=>'Second','Three'=>'Third','Four'=>'Fourth');
$second=array('One'=> 'First','Two'=>'2nd','Third'=>'3rd','Fourth'=>'Fourth');
$result1=array_diff_key($first,$second);
while (list ($key, $val) = each ($result1)) {
echo "$key -> $val <br>";
}
Output is here.
Three -> Third
Four -> Fourth
Keys of the first index are retained. ( no re-indexing done here)
← Subscribe to our YouTube Channel here