PHP array_diff_uassoc() function
In this chapter you will learn:
- Definition for PHP array_diff_uassoc() function
- Syntax for PHP array_diff_uassoc() function
- Parameter for PHP array_diff_uassoc() function
- Example - Compare the keys and values of two arrays use a user-defined function to compare the keys
Definition
The array_diff_uassoc() function compares the arrays with a user-defined function and returns the differences.
Syntax
PHP array_diff_uassoc() function has the following syntax.
array_diff_uassoc(array1,array2,array3...,myfunction);
Parameter
Parameter | Is Required | Description |
---|---|---|
array1 | Required. | Array to compare from |
array2 | Required. | Array to compare against |
array3,... | Optional. | More arrays to compare against |
myfunction | Required. | A string that define a callable comparison function. |
The comparison function must return an integer <, =, or > than 0 if the first argument is less than, equals, or greater than the second argument
Example
Compare the keys and values of two arrays use a user-defined function to compare the keys, and return the differences:
<?php//from j a v a2s .c o m
function myfunction($a,$b){
if ($a===$b){
return 0;
}
return ($a>$b)?1:-1;
}
$a1=array("a"=>"A","b"=>"B","c"=>"C");
$a2=array("d"=>"D","b"=>"B","e"=>"E","j"=>"java2s.com");
$result=array_diff_uassoc($a1,$a2,"myfunction");
print_r($result);
?>
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
- Syntax for PHP array_diff_ukey() function
- Definition for PHP array_diff_ukey() function
- Parameter for PHP array_diff_ukey() function
- Example - Compare the keys of two arrays using a user-defined key comparison function, and return the differences
Home » PHP Tutorial » PHP Array Functions