The array_key_exists () function checks whether a specified key exists in an array. if the key exists, true is returned. otherwise, false array_key_exists () is returned. definition and usage
The array_key_exists () function checks whether a specified key exists in an array. if the key exists, true is returned; otherwise, false is returned.
Syntax
Array_key_exists (key, array)
Parameter description
Key is required. Specifies the key name.
Array is required. Specifies the input array.
Example 1
"Dog","b"=>"Cat"); if (array_key_exists("a",$a)) { echo "Key exists!"; } else { echo "Key does not exist!"; } ?>
Output:
Key exists!
Example 2
"Dog","b"=>"Cat"); if (array_key_exists("c",$a)) { echo "Key exists!"; } else { echo "Key does not exist!"; } ?>
Output:
Key does not exist!
Example 2
Output:
Key exists!
For more information about the sequence of php array functions, see array_key_exists ()-Search for the existence of array key names!