Compare keys and values of two arrays with two user functions for comparison and return differences in PHP
Description
The following code shows how to compare keys and values of two arrays with two user functions for comparison and return differences.
Example
//from w ww.j av a2 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_udiff_uassoc($a1,$a2,"myfunction_key","myfunction_value");
print_r($result);
?>
The code above generates the following result.