PHP Array key_exists


The PHP array_key_exists() function checks whether a given key name or index exists in the array, returns TRUE if it exists, and FALSE otherwise.


bool array_key_exists(mixed key, array search)

The key argument is the given key name or index, which can be any value that can be used as an array index.

The array_key_exists() function is also available for objects, see the PHP Classes and Objects.


$arr_a = array('id' => 1, 'name' => "admin");
if (array_key_exists('name', $arr_a)) {
    echo 'The key name exists in the array $arr_a';
} else {
    echo 'The key name not exists in the array $arr_a';

Example output results are as follows:

The key name exists in the array $arr_a


The array_key_exists() function returns TRUE for array elements that are null. To check if an array element is null, use isset().

Copyright 2014-2017 by All Rights Reserved.