Compare keys and values of two arrays, return matches with a user-defined key comparison function in PHP
Description
The following code shows how to compare keys and values of two arrays, return matches with a user-defined key comparison function.
Example
//w ww . 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("d"=>"red","b"=>"Basic","e"=>"blue");
$result=array_intersect_uassoc($a1,$a2,"myfunction");
print_r($result);
?>
The code above generates the following result.