|
|
PHP array_intersect_key() Function
|
Tutorials » Php »
|
Topic |
What is array_intersect_key() Function?
|
|
Explanation |
|
The "array_intersect_key()" function is used to compute the intersection of
array elements, only if the keys are present in all other arrays.
Syntax:
array_intersect_key(array1,array2,array3.........)
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
<?php
$a = array (0=>'Blue',1=>'Green', 2=>'Orange', 3=>'Pink');
$b = array (4=>'Red', 2=>'Green', 3=>'Orange');
print_r(array_intersect_key($a,$b));
?>
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.
|
|
A Note |
Learn PHP programming language tutorial with simple and neat example. Hope you enjoy this free tutorial.
Do give us your valuable feedback and suggestions on this online tutorial. This is a Copyright Content.
|
|
|
|