How to use array_diff_uassoc() function to get the difference between arrays checked by a user callback function in PHP

1 Answer

0 votes
function key_compare_function($a, $b)
{
    if ($a === $b) {
        return 0;
    }
    return ($a > $b)? 1: -1;
}

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


// [0] => ddd is in the output because in the second argument "ddd" has the key 1
   
/*
run: 

Array ( [b] => bbb [c] => ccc [0] => ddd ) 

*/

 



answered May 16, 2016 by avibootz
...