PHP array_intersect_key() Function

What is array_intersect_key() Function?


The "array_intersect_key()" function is used to compute the intersection of array elements, only if the keys are present in all other arrays.



In the above syntax keys of "array1" is compared with other array elements, to return an array with values of keys that are present in all other arrays.

Example :

$a = array (0=>'Blue',1=>'Green', 2=>'Orange', 3=>'Pink');
$b = array (4=>'Red', 2=>'Green', 3=>'Orange');
Result :

Array ( [2] => Orange [3] => Pink )

In the above example the two arrays "$a","$b" when compared for keys, returns "Orange","Pink", as the keys 3,2 are present in both the arrays.

PHP Topics

Ask Questions

Ask Question