Example 1 — Check If a Key Exists
This example checks one key that is in the array and one that is not.
<?php
$user = ["name" => "Asha", "email" => null];
var_dump(key_exists("name", $user));
var_dump(key_exists("age", $user)); How It Works
- $user has the keys name and email.
- "name" is one of the keys, so key_exists() returns true.
- "age" is not a key in the array, so the result is false.
- var_dump() prints both booleans.

