What is PHP array_intersect() Function ?
The array_intersect()
function compares the values of two or more arrays and returns the matches. The keys are not considered in the comparison, only the values are checked.
The basic syntax of the array_intersect()
function is given with:
array_intersect(array1, array2, array3...);
The array_intersect()
function accepts the following parameters.
Parameter | Description |
---|---|
array1 | Required. Specifies the array to compare from. |
array2 | Required. Specifies an array to compare against. |
... | Optional. Specifies more arrays to compare against. |
The following example shows the array_intersect()
function in action.
Output :
Array
(
[0] => web
[1] => designing
[2] => house
)
Another Example :
The following example shows how to use this function to compare an array against two other arrays.
Output :
Array
(
[0] => web
[2] => house
)