Definition
The array_uintersect_assoc() function compares the values of two or more arrays and returns the matches with additional key check using a user-defined value comparison function.
Syntax
array_uintersect_assoc(array1, array2, array3, ..., function)
Parameters
Parameter | Description |
---|---|
array1 |
Required. The array to compare from. |
array2 |
Required. An array to compare against. |
array3... |
Optional. More arrays to compare against. |
function |
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($x, $y){
$x = strtolower($x);
$y = strtolower($y);
if($x == $y){
return 0;
}
return ($x < $y) ? -1 : 1;
}
$array1 = array("a" => "apple", "b" => "ball", "c" => "cat", "d" => "dog");
$array2 = array("a" => "Apple", "B" => "ball", "c" => "camel", "d" => "DOG");
$result = array_uintersect_assoc($array1, $array2, "compare");
print_r($result);