PHP array_intersect() Function
Last Updated : 17 Mar 2025
The array_intersect( ) function is used to Computes the intersection of arrays. It compares two or more arrays and returns an array containing all the values of the first array that are present in other arrays. In this operation, keys are preserved. This function was introduced in PHP 4.0.1.
Syntax
Parameter
| Parameter | Description | Is compulsory |
|---|---|---|
| array1 | The array to compare form. | compulsory |
| array2 | An array to compare against. | compulsory |
| array3 | More arrays to compare against. | Optional |
Return Type
It returns an array containing the entries from array1 that are present in all of the other arrays.
EXAMPLE 1
Output:
Array ( [a] => java [0] => python )
EXAMPLE 2
Output:
Array ( [a] => chess )
EXAMPLE 3
Output:
Array ( [Orange] => 100 [Apple] => 200 [Banana] => 300 )
EXAMPLE 4
Output:
Array ( [2] => rishi [3] => ayush )
Next TopicPhp-array-intersect-key-function