English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The PHP array_intersect_assoc() function compares arrays and returns the intersection of two arrays (comparing key names and key values).
array array_intersect_assoc ( array $array1, array $array2 [, array $array3 ...] );
array_intersect_assoc() returns an array that contains all the values that1 also appear in all other parameter arrays. Note that unlike array_intersect(), the key name is also used for comparison.
Serial Number | Parameters and Description |
---|---|
1 | array1(Required) The first array is the array that other arrays will be compared with. |
2 | array2(Required) This is an array to be compared with the first array |
3 | array3(Optional) This is an array to be compared with the first array |
Returns an array that contains all the values that1 also appear in all other parameter arrays.
array_intersect_assoc() function calculates the intersection of arrays with index checking
<?php $input1 = array("a" => "black", "red", "blue"); $input2 = array("a" => "black", "yellow", "red"); $result = array_intersect_assoc($input1, $input2); print_r($result); ?>Test and see‹/›
Output result:
Array ( [a] => black )