Easy Tutorial
❮ Func Filesystem File Put Contents Func Mysqli Stmt Init ❯

PHP array_intersect_key() Function

Complete PHP Array Reference Manual

Example

Compare the keys of two arrays and return the intersection:


Definition and Usage

The array_intersect_key() function is used to compare the keys of two (or more) arrays and return the intersection.

This function compares the keys of two (or more) arrays and returns an array of intersecting keys. This array includes all keys present in the first array (array1) that are also present in any of the other parameter arrays (array2, array3, etc.).


Syntax

Parameter Description
array1 Required. The first array to compare with the other arrays.
array2 Required. An array to compare against the first array.
array3,... Optional. Additional arrays to compare against the first array.

Technical Details

Return Value: Returns an array containing all the keys from array1 that are present in all of the other arrays (array2, array3, etc.).
PHP Version: 5.1.0+
--- ---

More Examples

Example 1

Compare the keys of two numeric arrays and return the intersection:

Example 2

Compare the keys of three arrays and return the intersection:


❮ Func Filesystem File Put Contents Func Mysqli Stmt Init ❯