PHP array_intersect_assoc() Function

What is array_intersect_assoc() Function?

Explanation

The "array_intersect_assoc()" function is used compute the intersection of arrays with additional index check.

Syntax:


array_intersect_assoc(array1,array2,array3.........)

In the above syntax values and keys of "array1" is compared with other arrays, to return an array with the values and keys that are present in all other arrays.

Example :


<?php
$a = array (0=>'Blue',1=>'Green', 2=>'Orange', 3=>'Pink');
$b = array (0=>'Red', 1=>'Green', 3=>'Violet');
print_r(array_intersect_assoc($a,$b));
?>
Result :

Array ( [1]=> Green )

In the above example the two arrays "$a", "$b" when compared for keys and values, returns "Green" in an array.

PHP Topics


Ask Questions

Ask Question