Array Intersection : array_intersect « Data Structure « PHP






Array Intersection

 
<?php
$first = array('e', 'h', 'r', 'j', 'b');
$last = array('w', 'e', 'c');

$intersection = array_intersect($last, $first);

echo '<p>';
foreach ($intersection as $v) { echo "{$v} "; }
echo "</p>\n";
?>
  
  








Related examples in the same category

1.array_intersect
2.array_intersect( ) function returns a new array containing all the values of array $arr1 that exist in array $arr2.
3.array_intersect_assoc
4.Intersecting two arrays that have no duplicate keys, all the keys will be retained.