How to use array_diff_ukey() function to get the difference between arrays with callback function for key compare in PHP

1 Answer

0 votes
function key_compare_function($key1, $key2)
{
    if ($key1 == $key2)
        return 0;
    else if ($key1 > $key2)
        return 1;
    else
        return -1;
}

$arr1 = array("a" => "aaa", "b" => "bbb", "c" => "ccc", "k" => "ddd");
$arr2 = array("a" => "aaa", "c" => "fff", "d" => "ddd");
$result = array_diff_ukey($arr1, $arr2, "key_compare_function");
print_r($result);

 
/*
run: 

Array ( [b] => bbb [k] => ddd ) 

*/

 



answered May 16, 2016 by avibootz
...