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 the array1An array of all values of the parameters, which 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 the array1All entries with keys that appear in all parameters. If there are any errors, it will return FALSE.
Returns an array that contains all entries that appear in $input1 and appear in all other parameter arrays $input2 of the values of the key names.
<?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 )