array_intersect_assoc()
array_intersect_assoc() — Computes the intersection of arrays with additional index check.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4 >= 4.3.0, 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_assoc() returns an array containing all the values of array that are present in all the arguments. Note that the keys are also used in the comparison unlike in array_intersect().
Signature
array_intersect_assoc(array $array, array ...$arrays): array
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $array | array | The array with master values to check. |
| ...$arrays | array | Arrays to compare values against. |
Return value
Returns an associative array containing all the values in array that are present in all of the arguments.
Example
A runnable snippet:
$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); $array2 = array("a" => "green", "b" => "yellow", "blue", "red"); $result_array = array_intersect_assoc($array1, $array2); print_r($result_array);
Output:
Array ( [a] => green )
Changelog
| Version | Change |
|---|---|
| 8.0.0 | This function can now be called with only one parameter. Formerly, at least two parameters have been required. |
See also
array_intersect(), array_uintersect_assoc(), array_intersect_uassoc(), array_uintersect_uassoc(), array_diff(), array_diff_assoc()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page array_intersect_assoc() (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.