PHP array_intersect_key() Function
Last Updated : 17 Mar 2025
The array_intersect_key( ) function computes the intersection of arrays using keys for comparison. This function compares the keys of two or more arrays and returns the matches. This function compares the keys of two or more arrays and returns an array that contains the entries from array1 that are present in array2, array3, etc. This function was introduced in PHP 5.1.
Syntax
Parameter
| Parameter | Description | Is compulsory |
|---|---|---|
| array1 | The first array is the array that the others will be compared with. | compulsory |
| array2 | An array to be compared with the first array. | compulsory |
| array3 | An array to be compared with the first array. | Optional |
Return Type
It returns an array containing the entries from array1 that are present in all of the other arrays.
EXAMPLE 1
Output:
Array ( [0] => java [1] => php [2] => python )
EXAMPLE 2
Output:
Array ( [1] => ajay [2] => ashish )
EXAMPLE 3
Output:
Array ( [yellow] => 1 [green] => 3 )
EXAMPLE 4
Output:
Array ( [sachin] => 100 [ganguly] => 300 )
Next TopicPhp-array-intersect-uassoc-function