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

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP array_intersect_key() Function Usage and Example

PHP Array Function Manual

The PHP array_intersect_key() function uses key names to calculate the intersection of arrays.

Syntax

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

Definition and Usage

It returns an array containing the array1An array of all values of the parameters, which have matching keys existing in all parameters.

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 the array to be compared with the first array

3

array3(Optional)

This is the array to be compared with the first array

Returns Value

Returns an associative array that contains the array1All entries with keys that appear in all parameters. If there are any errors, it will return FALSE.

Online Examples

Returns an array that contains all entries that appear in $input1 and appear in all other parameter arrays $input2 of the values of the key names.

<?php
   $input1 = array('black' => 1, 'red' => 2, 'green' => 3 );
   $input2 = array('green' => 4, 'black' => 5, 'pink' => 6,);
   
   $result = array_intersect_key($input1, $input2);
   print_r($result);
?>
Test and See‹/›

Output Result:

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

 PHP Array Function Manual