Example 1 — Check If a Key Exists
Look for keys in a small user array.
<?php
$user = ["name" => "Ana", "age" => 25];
echo array_key_exists("name", $user) ? "yes" : "no", PHP_EOL;
echo array_key_exists("email", $user) ? "yes" : "no", PHP_EOL; How It Works
- Create an array. It has the keys
nameandage. - Search for name. The key exists, so the function returns
true. - Search for email. There is no such key, so it returns
false. - Print a word. The ternary turns the result into yes or no.

