Array_key_exists () 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
Copy codeThe Code is as follows:
<? Php
$ A = array ("a" => "Dog", "B" => "Cat ");
If (array_key_exists ("a", $ ))
{
Echo "Key exists! ";
}
Else
{
Echo "Key does not exist! ";
}
?>
Output:
Key exists!
Example 2
Copy codeThe Code is as follows:
<? Php
$ A = array ("a" => "Dog", "B" => "Cat ");
If (array_key_exists ("c", $ ))
{
Echo "Key exists! ";
}
Else
{
Echo "Key does not exist! ";
}
?>
Output:
Key does not exist!
Example 2
Copy codeThe Code is as follows:
<? Php
$ A = array ("Dog", Cat ");
If (array_key_exists (0, $ ))
{
Echo "Key exists! ";
}
Else
{
Echo "Key does not exist! ";
}
?>
Output:
Key exists!