xxxxxxxxxx
PHP function key_exists($key, array $array) bool
------------------------------------------------
Checks if the given key or index exists in the array. The name of this function is array_key_exists() in PHP > 4.0.6.
Parameters:
int|string--$key--Value to check.
array--$array--An array with keys to check.
Returns:true on success or false on failure.
xxxxxxxxxx
<?php
$exampleArray = array(
'key1' => 'value1',
'key2' => 'value2',
'key3' => 'value3'
);
$desiredKey = 'key2';
if (array_key_exists($desiredKey, $exampleArray)) {
echo "The key '$desiredKey' exists in the array.";
} else {
echo "The key '$desiredKey' does not exist in the array.";
}
?>