PHP

PHP Menu

PHP

array_intersect_key() Function - Definition, Syntax, Parameters, Examples

Definition

The array_intersect_key() function compares the keys of two or more arrays, and return an array that contains the entries from array1 that are present in array2, array3, etc.

Syntax

array_intersect_key(array1, array2, array3, ...)

Parameters

Parameter Description
array1 Required. The array to compare from.
array2 Required. An array to compare against.
array3 Optional. More arrays to compare against.

Example

<?php
$ages1 = array("Mark" => 22, "Jeff" => 32, "Mike" => 28); $ages2 = array("Fred" => 22, "John" => 32, "Robin" => 28); $ages3 = array("Mark" => 23, "John" => 32, "Mike" => 36); $result = array_intersect_key($ages1, $ages2); print_r($result); echo "<br>"; $result = array_intersect_key($ages1, $ages3); print_r($result); echo "<br>"; $result = array_intersect_key($ages1, $ages2, $ages3); print_r($result); echo "<br>";

Introduction

PHP Basics

PHP Advance

PHP OOP

PHP Functions and Methods