PHP Array key_exists


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.

grammar:

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.

example:

$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

Tip

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 DeveloperTut.com. All Rights Reserved.
TwitterGoogle+Facebook