PHP array_intersect_assoc

Last Updated: February 12, 2022

array_intersect_assoc : Computes the intersection of arrays and returns the results in an array. To find the intersection the keys and values of the arrays are compared

Syntax

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

Supports (PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)

Parameters

Parameter Description
array Required.  array with values to check intersected values
arrays Required. arrays to be compared with the first array

Return Value

Return an array containing elements that are also appearing in other arrays

Example

<?php
$array1 = array("1" => "one", "2" => "two", "3" => "three", "four");
$array2 = array("1" => "one", "3" => "three", "four", "five");
$result_array = array_intersect_assoc($array1, $array2);
print_r($result_array);
?>

Output

Array ( [1] => one [3] => three [4] => four ) 
Test