HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
PHP Array Reference : Check if the key "Volvo" exists in an array
The array_key_exists() function checks an array for a specified key, and returns true if the key exists and false if the key does not exist.
Parameter | Description |
---|---|
key | Required. Specifies the key |
array | Required. Specifies an array |
Return Value: | Returns TRUE if the key exists and FALSE if the key does not exist |
---|---|
PHP Version: | 4.0.7+ |
Check if the key "Toyota" exists in an array:
<?php
$a=array("Volvo"=>"XC90","BMW"=>"X5");
if (array_key_exists("Toyota",$a))
{
echo "Key exists!";
}
else
{
echo "Key does not exist!";
}
?>
Check if the integer key "0" exists in an array:
<?php
$a=array("Volvo","BMW");
if (array_key_exists(0,$a))
{
echo "Key exists!";
}
else
{
echo "Key does not exist!";
}
?>
❮ PHP Array Reference