Definition
The array_udiff_uassoc() function compares the keys and values of two or more arrays and returns the differences using the user-defined key and value comparison functions.
Syntax
array_udiff_uassoc(array1, array2, array3, ..., myfunc_value, myfunc_key)
Parameters
Parameter | Description |
---|---|
array1 |
Required. The array to compare from. |
array2 |
Required. An array to compare against. |
array3... |
Optional. More arrays to compare against. |
myfunc_key |
Required. The name of the user-defined function that compares the array keys. A string that define a callable comparison function. The comparison function must return an integer <, =, or > than 0 if the first argument is <, =, or > than the second argument. |
myfunc_value |
Required. The name of the user-defined function that compares the array values. A string that define a callable comparison function. The comparison function must return an integer <, =, or > than 0 if the first argument is <, =, or > than the second argument. |
Example
<?php
function compareKey($x, $y) {
if($x == $y){
return 0;
}
return ($x < $y) ? -1 : 1;
}
function compareValue($x, $y) {
// Converting value to lowercase
$x = strtolower($x);
$b = strtolower($y);
if ($x == $y) {
return 0;
}
return ($x < $y) ? -1 : 1;
}
$array1 = array("a" => "apple", "b" => "ball", "c" => "cat", "dog");
$array2 = array("a" => "APPLE", "B" => "ball", "c" => "Cat");
$result = array_udiff_uassoc($array1, $array2, "compareValue", "compareKey");
print_r($result);