• PHP Video Tutorials

PHP - Function array_intersect_assoc()



Syntax

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

Definition and Usage

It returns an array containing all the values of array1 that are present in all the arguments.

Parameters

Sr.No Parameter & Description
1

array1(Required)

The first array is the array that the others 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 Values

It returns an array containing all the values of array1 that are present in all the arguments.

Example

Try out following example −

<?php
   $input1 = array("a" => "black", "red", "blue");
   $input2 = array("a" => "black", "yellow", "red");
   $result = array_intersect_assoc($input1, $input2);
   
   print_r($result);
?> 

This will produce the following result −

Array ( [a] => black )
php_function_reference.htm
Advertisements