"XC90","BMW"=>"X5"); if (array_key_exists("Volvo",$a)) { "> "XC90","BMW"=>"X5"); if (array_key_exists("Volvo",$a)) { " />
Easy Tutorial
❮ Func Ftp Rawlist Func Array Key First ❯

PHP array_key_exists() Function

Complete PHP Array Reference Manual

Example

Check if the key "Volvo" exists in the array:

<?php
$a=array("Volvo"=>"XC90","BMW"=>"X5");
if (array_key_exists("Volvo",$a))
{
    echo "Key exists!";
}
else
{
    echo "Key does not exist!";
}
?>

Definition and Usage

The array_key_exists() function checks if a specified key exists in an array. It returns true if the key exists and false if the key does not exist.

Tip: Remember that if you omit the key when specifying an array, integer keys starting from 0 will be generated. (See Example 2)


Syntax

Parameter Description
key Required. Specifies the key name.
array Required. Specifies the array.

Technical Details

Return Value: Returns TRUE if the key exists, FALSE if the key does not exist.
PHP Version: 4.0.7+
--- ---

More Examples

Example 1

Check if the key "Toyota" exists in the array:

<?php
$a=array("Volvo"=>"XC90","BMW"=>"X5");
if (array_key_exists("Toyota",$a))
{
    echo "Key exists!";
}
else
{
    echo "Key does not exist!";
}
?>

Example 2

Check if the integer key "0" exists in the array:

<?php
$a=array("Volvo","BMW");
if (array_key_exists(0,$a))
{
    echo "Key exists!";
}
else
{
    echo "Key does not exist!";
}
?>

Complete PHP Array Reference Manual

❮ Func Ftp Rawlist Func Array Key First ❯