array_diff_key(): Difference between two arrays with respect to Keys

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');

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


* indicates required
Subscribe to plus2net

    Post your comments , suggestion , error , requirements etc here .

    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2023 All rights reserved worldwide Privacy Policy Disclaimer