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

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP array_key_exists() function usage and example

PHP Array Function Manual

The PHP array_key_exists() function checks if there is a specified key name or index in the array

Syntax

bool array_key_exists ($key, $array);

Definition and Usage

When the key key exists in the array ($array), array_key_exists() returns TRUE.

Parameter

Serial NumberParameters and Description
1

key(Required)

The key to be searched for.

2

array(Required)

This is the array to be searched

Return value

If the given key exists in the array, it returns TRUE, otherwise it returns FALSE.

Online Example

Check if the specified key name exists in the array

<?php
   $input = array('first' => 10, 'second' => 400);
   
   if (array_key_exists('first', $input)) {
      echo "The first element exists in the array";
   }
?>
Test and see‹/›

Output result:

The first element exists in the array

PHP Array Function Manual