How to detect if this dictionary key exists in PHP?
The array_key_exists() function checks an array for a specified key, and returns true if the key exists and false if the key does not exist.
php key_exists
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.
Example 2
<?php
$a=array("Volvo"=>"XC90","BMW"=>"X5");
if (array_key_exists("Toyota",$a))
{
echo "Key exists!";
}
else
{
echo "Key does not exist!";
}
?>