-
- $a=array("a"=>"Dog","b"=>"Cat");
- if (array_key_exists("a",$a))
- {
- echo "Key exists!";
- }
- else
- {
- echo "Key does not exist!";
- }
- ?>
Copy code
Output:
Key exists!
Example 2:
-
- $a=array("a"=>"Dog","b"=>"Cat");
- if (array_key_exists("c",$a))
- {
- echo "Key exists!";
- }
- else
- {
- echo "Key does not exist!";
- }
- ?>
Copy code
Output:
Key does not exist!
Example 3:
-
- $a=array("Dog",Cat");
- if (array_key_exists(0,$a))
- {
- echo "Key exists!";
- }
- else
- {
- echo "Key does not exist!";
- }
- ?>
Copy code
output:
Key exists!
|