PHP array_key_exists() Function

The array_key_exists() function checks if a specified key exists in an array. It returns true if the key is found, otherwise false.

Key Features of array_key_exists()

Syntax of array_key_exists()

Syntax

bool array_key_exists(mixed $key, array $array);

Example Using array_key_exists()

The following example demonstrates how array_key_exists() is used:

Example


$array = ["language" => "PHP", "framework" => "Laravel"];
        
if (array_key_exists("framework", $array)) {
        echo "Key 'framework' exists in the array!";
} else {
echo "Key 'framework' does not exist.";
}
    
    

Output

Key 'framework' exists in the array!