PHP - Function array_intersect_key()


Advertisements


Syntax

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

Definition and Usage

Returns an array containing all the values of array1 which have matching keys that are present in all the arguments.

Parameters

Parameter Description
array1 Required. The first array is the array that the others will be compared with.
array2 Required. An array to be compared with the first array
array3 Optional. An array to be compared with the first array

Return Values

Returns FALSE if there is any error.

Example

Try out following example −

<?php
   $array1 = array('blue'  => 1, 'red'  => 2, 'green'  => 3 );
   $array2 = array('green' => 4, 'blue' => 5, 'yellow' => 6,);
   
   $result = array_intersect_key($array1, $array2);
   print_r($result);
?> 

This will produce the following result −

Array ( [blue]  => 1 [green] => 3 )

php_function_reference.htm

Advertisements