PHP array_intersect function

Last Updated: February 12, 2022

array_intersect : Computes the intersection of arrays

Syntax

array_intersect(array $array, array ...$arrays): array

Parameters

Parameter Description
array Required. array with values to check intersected values
arrays Required. arrays to be compared with the first array

Return Value

Return an array containing elements that are also appearing in other arrays

Example

<?php
$array1 = array("1" => "one", "2" => "two", "3" => "three", "four");
$array2 = array("1" => "one", "3" => "three", "four", "five");
$result_array = array_intersect_key($array1, $array2);
print_r($result_array);
?>

Output

Array ( [1] => one [3] => three [4] => four ) 
Test