Definition :
The array_intersect_key()
function compares the keys of two or more arrays and returns the matches. The keys values are not considered in the comparison, only the keys are checked.
The basic syntax of the array_intersect_key()
function is given with:
array_intersect_key(array1, array2, ...);
The array_intersect_key()
function accepts the following parameters.
Parameter | Description |
---|---|
array1 | Required. Specifies the array to compare from. |
array2 | Required. Specifies an array to compare keys against. |
array3 | Optional. Specifies more arrays to compare keys against. |
The following example shows the array_intersect_key()
function in action.
Output :
Array
(
[a] => Web
[b] => designing
)
Another Example:
Compare the keys of two indexed arrays, and return the matches:
Output :
Array
(
[0] => Web
[1] => designing
[2] => house
)
Example3:
Compare the keys of three arrays, and return the matches:
Output :
Array
(
[a] => Web
)