English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

PHP array_intersect_assoc() Function Usage and Example

PHP Array Function Manual

The PHP array_intersect_assoc() function compares arrays and returns the intersection of two arrays (comparing key names and key values).

Syntax

array array_intersect_assoc ( array $array1, array $array2 [, array $array3 ...] );

Definition and Usage

array_intersect_assoc() returns an array that contains all the values that1 also appear in all other parameter arrays. Note that unlike array_intersect(), the key name is also used for comparison.

Parameter

Serial NumberParameters and Description
1

array1(Required)

The first array is the array that other arrays will be compared with.

2

array2(Required)

This is an array to be compared with the first array

3

array3(Optional)

This is an array to be compared with the first array

Return value

 Returns an array that contains all the values that1 also appear in all other parameter arrays.

Online Example

array_intersect_assoc() function calculates the intersection of arrays with index checking

<?php
   $input1 = array("a" => "black", "red", "blue");
   $input2 = array("a" => "black", "yellow", "red");
   $result = array_intersect_assoc($input1, $input2);
   
   print_r($result);
?>
Test and see‹/›

Output result:

Array ( [a] => black )

PHP Array Function Manual