I l@ve RuBoard Previous Section Next Section

array_intersect

array array_intersect(array array_1, array array_2, [array ...]) 

array_1

First array to intersect

array_2

Second array to intersect

...

Further arrays to intersect

Returns an array containing elements that are present in all array arguments.

Returns:

Array on success; NULL on failure

Description:

This function accepts at least two arrays as arguments, and returns an array containing all elements that appear in all given array arguments. The keys of the resultant array are those of the matching elements from the first array argument.

Version:

PHP 4 since 4.0.1

Example:

Calculate the intersection of three arrays
$array_1 = array('brown bat', 'fruit bat', 'wombat', 'baseball bat'); 
$array_2 = array('goatsucker', 'wombat', 'mongoose', 'mon ami'); 
$array_3 = array('wombat', 'goatsucker', 'mongoose', 'baseball bat'); 

$intersection = array_intersect($array_1, $array_2, $array_3); 
print_r($intersection); 

/* Expected output: 
 * 
 * Array 
 * (
 * [2] => wombat 
 * ) 
 * 
 * Note that the key is '2', which is the matching key from the first array. 
 */ 
    I l@ve RuBoard Previous Section Next Section