Description :
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.
Tip: Remember that if you skip the key when you specify an array, an integer key is generated, starting at 0 and increases by 1 for each value.
The basic syntax of the array_key_exists()
function is given with:
array_key_exists(key, array);
The array_key_exists()
function accepts the following parameters.
Parameter | Description |
---|---|
key | Required. Specifies the key to check. |
array | Required. Specifies the target array in which key will be checked. |
Example1 :
Following Example to check the key "de" exits or not.
Output : Key exists!
Example2 :
Following Example to check the key "Iphone" exits or not.
Output : Key does not exist!
Example3 :
Check if the integer key "0" exists in an array:
Output : Key exists!