PHP 8 reference · Array Functions

PHP array_intersect() Function

Return the values of the first array that are also present in all the other arrays. Keys come from the first array.

PHP 8 Since 4.0

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

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

Parameters

ParameterDescription
array The input array.
arrays Arrays to compare against.

Return value

The common values.

Examples

Common valuesTry it yourself
<?php
print_r(array_intersect(["php", "sql", "css"], ["sql", "php", "go"]));

Output

Array
(
    [0] => php
    [1] => sql
)
Shared itemsTry it yourself
<?php
$ada = ["php", "python", "sql"];
$alan = ["sql", "go", "php"];
echo "shared skills: ", implode(", ", array_intersect($ada, $alan)), "\n";

Output

shared skills: php, sql

Version history

VersionChange
PHP 4.0Added

In other languages

Was this page helpful?