Array Intersect Function in PHP

In this article I am going to explain about PHP array intersect function.
  • 1771

PHP array_intersect Function

The array_intersect function computes the intersection of an array and returns an array with the key and value from first array but the values and keys are present in all of the other array.

Syntax
 

array_intersect(array1, array2,................)

Parameter

The parameters for the array_intersect function are:

Parameter Description
array1 It specifies an array, who is compare from others.
array2 It specifies an array to compare against first array.
................ It specifies more array to compare against first array.

Example

An example of the array_intersect function is:

<?php

echo "<pre>";

$val = array("a" => "Apple", "b" => "Mango", "c" => "Orange", "Banana");

$val2 = array("a" => "Apple", "b"=>"Raspberry", "banana");

$interscet = array_intersect($val,$val2);

print_r($interscet);

?>

Output

array-intersect-function-in-php.jpg

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.