Compare keys and values of two arrays with two user functions for comparison and return matches in PHP
Description
The following code shows how to compare keys and values of two arrays with two user functions for comparison and return matches.
Example
//from ww w.j a va2 s. c o m
<?php
function myfunction_key($a,$b){
if ($a===$b){
return 0;
}
return ($a>$b)?1:-1;
}
function myfunction_value($a,$b){
if ($a===$b){
return 0;
}
return ($a>$b)?1:-1;
}
$a1=array("a"=>"red","b"=>"green","c"=>"blue");
$a2=array("a"=>"red","b"=>"green","c"=>"green");
$result=array_uintersect_uassoc($a1,$a2,"myfunction_key","myfunction_value");
print_r($result);
?>
The code above generates the following result.