Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP array_intersect_assoc() Function

PHP array_intersect_assoc() Function

PHP Array ReferenceComplete PHP Array Reference Manual

Example

Compare two arrays by theirkeys and values, and return the intersection:

"red","b"=>"green","c"=>"blue","d"=>"yellow"); $a2=array("a"=>"red","b"=>"green","c"=>"blue"); $result=array_intersect_assoc($a1,$a2); print_r($result); ?>

Run Example »


Definition and Usage

The array_intersect_assoc() function compares two (or more) arrays by theirkeys and values, and returns the intersection.

This function compares the keys and values of two (or more) arrays and returns an intersection array containing all the keys and values in the compared array (array1) that are also present in any of the other argument arrays (array2 or array3 , etc.).


Syntax

array_intersect_assoc(

array1,array2,array3...

)

Parameters Description
array1 Required. The first array to compare with the other arrays.
array2 Required. An array to compare with the first array.
array3,... Optional. Other arrays to compare with the first array.

Technical Details

Return Value: Returns an intersection array containing all the keys and values in the compared array (array1) that are also present in any of the other argument arrays (array2 or array3 , etc.).
PHP Version: 4.3.0+

More examples

Example 1

Compare three arrays by theirkeys and values, and return the intersection:

"red","b"=>"green","c"=>"blue","d"=>"yellow"); $a2=array("a"=>"red","b"=>"green","g"=>"blue"); $a3=array("a"=>"red","b"=>"green","g"=>"blue"); $result=array_intersect_assoc($a1,$a2,$a3); print_r($result); ?>

Run Example »


PHP Array ReferenceComplete PHP Array Reference Manual