English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The PHP array_intersect_key() function uses key names to calculate the intersection of arrays.
array array_intersect_key ( array $array1, [array $array2 , [array $array3 ...] );
It returns an array containing array1An array of all values of the parameter, these values have matching keys existing in all parameters.
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 the array to be compared with the first array |
3 | array3(Optional) This is the array to be compared with the first array |
Returns an associative array that contains array1All entries with keys appearing in all parameters. If there are any errors, it will return FALSE.
Returns an array that contains all entries that appear in $input1 And also appears in all other parameter arrays $input2 The value of the key names in.
<?php $input1 = array('black' => 1, 'red' => 2, 'green' => 3 ); $input2 = array('green' => 4, 'black' => 5, 'pink' => 6,); $result = array_intersect_key($input1, $input2); print_r($result); ?>Test and see‹/›
Output result:
Array ( [black] => 1 [green] => 3 )