Definition
The array_intersect_uassoc() function compares the values of two or more arrays and returns the matches with additional key check using a user-defined key comparison function.
Syntax
array_intersect_uassoc(array1, array2, array3, ..., myfunction)
Parameters
Parameter | Description |
---|---|
array1 |
Required. The array to compare from. |
array2 |
Required. An 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 <, =, or > than the second argument. |
Example
<?php
function compare($a, $b){
// Converting key to lowercase
$a = strtolower($a);
$b = strtolower($b);
if($a == $b){
return 0;
}
return ($a < $b) ? -1 : 1;
}
$array1 = array("a" => "apple", "b" => "ball", "c" => "cat", "dog");
$array2 = array("A" => "APPLE", "B" => "ball", "c" => "camel");
$result = array_intersect_uassoc($array1, $array2, "compare");
print_r($result);
echo "<br>";
$array3 = array("a" => "airplane", "b" => "ball");
$result = array_intersect_uassoc($array1, $array2, $array3, "compare");
print_r($result);
echo "<br>";