PHP array_intersect()


array_intersect(array1,array2 [,array3 ...]) function returns the shared elements of array1 and other arrays.

<?PHP
	$arr1=array(1,2,3,4,5,6,7,8,9);
	$arr2=array(2,4,6,8);
	$arr3=array_intersect($arr1,$arr2);
	foreach($arr3 as $element) echo "$element, "; //2, 4, 6, 8,
?>

If more than 2 arrays are compared, only elements contained in all arrays will be returned.
<?PHP
	$arr1=array(1,2,3,4,5,6,7,8,9);
	$arr2=array(2,4,6,8);
	$arr3=array_intersect($arr1,$arr2,array(2,4));
	foreach($arr3 as $element) echo "$element, "; //2, 4
?>