Definition
The array_key_exists() function checks an array for a specified key, and returns true if the key exists and false if the key does not exist.
Syntax
array_key_exists(key, array)
Parameters
| Parameter | Description |
|---|---|
key |
Required. Specifies the key. |
array |
Required. Specifies an array. |
Example
<?php
$ages = array("Mark" => 22, "Jeff" => 32, "Mike" => 28);
if(array_key_exists("Jeff", $ages)){
echo "Key exists!";
} else {
echo "Key does not exist!";
}