PHP array_intersect_assoc() Function | PHP Array Functions

The array_intersect_assoc() function compares two or more arrays and returns an array with elements that have matching keys and values in all input arrays. It performs a strict comparison of both 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() works:

Example


$array1 = ["a" => "PHP", "b" => "JavaScript", "c" => "Python"];
$array2 = ["a" => "PHP", "b" => "C#", "c" => "Python"];

$result = array_intersect_assoc($array1, $array2);

print_r($result);

Output

Array ( [a] => PHP [c] => Python )