key_exists()
key_exists() — Alias of array_key_exists().
Built-in function of PHP 8.5. The manual lists it as available in PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
key_exists() is an alias of array_key_exists(): same parameters, same return value.
Signature
key_exists(string|int|float|bool|resource|null $key, array $array): bool
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $key | string|int|float|bool|resource|null | Value to check. |
| $array | array | An array with keys to check. |
Return value
Returns true on success or false on failure. Note: array_key_exists() will search for the keys in the first dimension only. Nested keys in multidimensional arrays will not be found. array_key_exists() will search for the keys in the first dimension only. Nested keys in multidimensional arrays will not be found.
Example
A runnable snippet:
$searchArray = ['first' => 1, 'second' => 4]; var_dump(array_key_exists('first', $searchArray));
Output:
bool(true)
All PHP 8.5 built-in functions
Reference card built from the PHP manual page key_exists() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.