Organizational Research By

Surprising Reserch Topic

Question:how to difference of arrays with additional index check which is performed by a user supplied callback function in php?



asked Sep 13, 2013 in PHP by rajesh
edited Sep 12, 2013
+1 vote
49 views



Related Hot Questions

1 Answer

0 votes

 

function key_compare_func($a, $b)
{
    if ($a === $b) {
        return 0;
    }
    return ($a > $b)? 1:-1;
}
 
$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red");
$array2 = array("a" => "green", "yellow", "red");
$result = array_diff_uassoc($array1, $array2, "key_compare_func");
print_r($result);
?>
 
he above example will output:
Array
(
    [b] => brown
    [c] => blue
    [0] => red
)
The equality of 2 indices is checked by the user supplied callback function.
answered Sep 13, 2013 by rajesh
edited Sep 12, 2013

...