array_intersect( ) function returns a new array containing all the values of array $arr1 that exist in array $arr2. : array_intersect « Data Structure « PHP






array_intersect( ) function returns a new array containing all the values of array $arr1 that exist in array $arr2.

 
array array_intersect ( array arr1, array arr2 [, array ...] )

<?
    $toppings1 = array("Pepperoni", "Cheese", "Anchovies", "Tomatoes");
    $toppings2 = array("Ham", "Cheese", "Peppers");
    $int_toppings = array_intersect($toppings1, $toppings2);

    var_dump($int_toppings);
?>
  
  








Related examples in the same category

1.Array Intersection
2.array_intersect
3.array_intersect_assoc
4.Intersecting two arrays that have no duplicate keys, all the keys will be retained.