Compare values of two arrays with user function to compare values and return differences in PHP
Description
The following code shows how to compare values of two arrays with user function to compare values and return differences.
Example
/*from www . j a v a 2 s.c om*/
<?php
function myfunction($a,$b){
if ($a===$b){
return 0;
}
return ($a>$b)?1:-1;
}
$a1=array("a"=>"red","b"=>"green","c"=>"blue");
$a2=array("a"=>"blue","b"=>"black","e"=>"blue");
$result=array_udiff($a1,$a2,"myfunction");
print_r($result);
?>
The code above generates the following result.