array_intersect_uassoc()
array_intersect_uassoc() — Computes the intersection of arrays with additional index check, compares indexes by a callback function.
Built-in function of PHP 8.5. The manual lists it as available in PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
array_intersect_uassoc() returns an array containing all the values of array that are present in all the arguments. Note that the keys are used in the comparison unlike in array_intersect().
Signature
array_intersect_uassoc(array $array, array ...$arrays, callable $key_compare_func): array callback(mixed $a, mixed $b): int
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $array | array | Initial array for comparison of the arrays. |
| ...$arrays | array | Arrays to compare keys against. |
| $key_compare_func | callable | The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second. |
Return value
Returns the values of array whose values exist in all of the arguments.
Example
A runnable snippet:
$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); $array2 = array("a" => "GREEN", "B" => "brown", "yellow", "red"); print_r(array_intersect_uassoc($array1, $array2, "strcasecmp"));
Output:
Array ( [b] => brown )
See also
array_intersect(), array_intersect_assoc(), array_uintersect_assoc(), array_uintersect_uassoc(), array_intersect_key(), array_intersect_ukey()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page array_intersect_uassoc() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.