PHP array_intersect() Function

The array_intersect() function compares two or more arrays and returns an array containing values present in all the arrays.

Key Features of array_intersect()

Syntax of array_intersect()

Syntax

array array_intersect(array $array1, array $array2, array ...$arrays);

Example Using array_intersect()

The following example demonstrates how array_intersect() is used:

Example


$array1 = ["PHP", "JavaScript", "Python"];
$array2 = ["JavaScript", "Ruby", "PHP"];

$result = array_intersect($array1, $array2);
print_r($result);

Output

Array ( [0] => PHP [1] => JavaScript )