PHP - Function array_key_exists()


Advertisements


Syntax

bool array_key_exists ( $key, $array );

Definition and Usage

Returns TRUE if the given key is set in the array. key can be any value possible for an array index.

Parameters

ParameterDescription
keyRequired. Key to be searched.
arrayRequired. Array to be searched

Return Values

Returns TRUE if the given key is set in the array otherwise FALSE.

Example

Try out following example:

<?php
$search_array = array('first' => 1, 'second' => 4);
if (array_key_exists('first', $search_array)) {
    echo "The 'first' element is in the array";
}
?> 

This will produce following result:

The 'first' element is in the array

php_function_reference.htm