PHP array_intersect_assoc() Function

The array_intersect_assoc() function compares two or more arrays and returns an array with elements that have matching keys and values.

Key Features of array_intersect_assoc()

Syntax of array_intersect_assoc()

Syntax


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

Example Using array_intersect_assoc()

The following example demonstrates how array_intersect_assoc() is used:

Example


$array1 = ["a" => "PHP", "b" => "JavaScript", "c" => "Python"];
$array2 = ["a" => "PHP", "b" => "Java", "d" => "Ruby"];
$result = array_intersect_assoc($array1, $array2);
print_r($result);

Output

Array ( [a] => PHP )