Contents of this section: PHP array function array_key_exists () Array_key_exists () defines and uses the array_key_exists () function to determine whether a specified key exists in an array, returns TRUE if the key exists, or false otherwise. The syntax array_key_exists (key,array) parameter describes key required. Specifies the key name. Array required. Specifies the input array. Example 1,php the array_key_exists () of an array function.
- $a =array ("a" and "Dog", "b" = "Cat");
- if (Array_key_exists ("a", $a))
- {
- echo "Key exists!";
- }
- Else
- {
- echo "Key does not exist!";
- }
- ?>
Copy CodeOutput: Key exists! Example 2,php the array_key_exists () of an array function.
- $a =array ("a" and "Dog", "b" = "Cat");
- if (Array_key_exists ("C", $a))
- {
- echo "Key exists!";
- }
- Else
- {
- echo "Key does not exist!";
- }
- ?>
Copy CodeOutput: Key does not exist! Example 3,php the array_key_exists () of an array function.
- $a =array ("Dog", Cat ");
- if (array_key_exists (0, $a))
- {
- echo "Key exists!";
- }
- Else
- {
- echo "Key does not exist!";
- }
- ?>
Copy CodeOutput: Key exists! |