The array_key_exists() function checks if the specified key exists in the array. The function returns true if the key exists and false if the key does not exist.
Syntax
array_key_exists(key, arr)
Parameters
key − Specify the key to be checked.
arr − The array wherein we will find the key.
Return
The array_key_exists() function returns true if the key exists and false if the key does not exist.
Example
<?php $arr = array("One"=>"Tennis","Two"=>"Football", "Three"=>"Cricket"); if (array_key_exists("Three",$arr)) { echo "Key is in the array!"; } else { echo "Key is not in the array!"; } ?>
Output
Key is in the array!