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', ...

Get PHP Functions Essential Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.