|
|
Tutorials » Php »
|
Topic |
What is array_intersect() Function?
|
|
Explanation |
|
The "array_intersect()" function is used to compute the intersection of arrays.
Syntax:
array_intersect(array1,array2,array3....)
In the above syntax values and keys of "array1" is compared with other arrays, returns the values from the "array1"
if it is present in all other arrays
Example:
<?php
$a = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4);
$b = array('orange' => 5, 'blue' => 6, 'green' => 7, 'red'=> 8);
print_r(array_intersect($a, $b));
?>
Result:
Array {["blue"]=> int(1) ["green"]=> int(3)}
In the above example the two arrays "$a", "$b" are compared for keys and values, returns an array
elements that 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.
|
|
|
|