CKTIS / PHP
array_key_exists()
Check a key at the first level independently of the stored value.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
array_key_exists(string|int|float|bool|resource|null $key, array $array): boolCheck a key at the first level independently of the stored value. A present key holding null succeeds, distinguishing a blank setting from an absent one. In PHP 8.4 the lookup key is normalized. A false key searches for integer key 0 and a null key searches for the empty string. Check nested paths one key at a time.
Signature
array_key_exists(string|int|float|bool|resource|null $key, array $array): bool
Example output
[true,false,false,true,true]
Examples
<?php
$settings = ['limit'=>null, 0=>'zero', ''=>'empty'];
echo json_encode([array_key_exists('limit', $settings), isset($settings['limit']), array_key_exists('page', $settings), array_key_exists(false, $settings), array_key_exists(null, $settings)]);
Result
[true,false,false,true,true]