array_key_exists() Definition and usage
array_key_exists() function determines whether the specified key exists in an array. If the key exists, it returns true, otherwise it returns false.
Syntax
array_key_exists(key,array)
Parameter Description
key Required. Specifies the key name.
array required. Specifies the input array.
Example 1
Copy the code The code is as follows:
$a=array("a"=>"Dog","b"=>"Cat");
if (array_key_exists("a",$a))
{
echo "Key exists!";
}
else
{
echo "Key does not exist!";
}
?>
Copy the code The code is as follows:
$a=array("a"=>"Dog","b"=>"Cat");
if (array_key_exists("c",$a))
{
echo "Key exists!";
}
else
{
echo "Key does not exist!";
}
?>
Copy the code The code is as follows:
$a=array("Dog",Cat");
if (array_key_exists(0,$a ))
{
echo "Key exists!";
}
else
{
echo "Key does not exist!";
}
?>
The above has introduced the array_key_exists of the PHP array function sequence - finding whether the array key exists, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.