array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'uk', ), 'this' => array ( 0 => 'function.array-key-exists.php', 1 => 'array_key_exists', 2 => 'Checks if the given key or index exists in the array', ), 'up' => array ( 0 => 'ref.array.php', 1 => 'Функції для роботи з масивами', ), 'prev' => array ( 0 => 'function.array-is-list.php', 1 => 'array_is_list', ), 'next' => array ( 0 => 'function.array-key-first.php', 1 => 'array_key_first', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/array/functions/array-key-exists.xml', ), 'history' => array ( ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); contributors($setup); ?>
(PHP 4 >= 4.0.7, PHP 5, PHP 7, PHP 8)
array_key_exists — Checks if the given key or index exists in the array
array_key_exists() returns true if the
given key is set in the array.
key can be any value possible
for an array index.
keyValue to check.
arrayAn array with keys to check.
Повертає true у разі успіху або false в разі помилки.
Зауваження:
array_key_exists() will search for the keys in the first dimension only. Nested keys in multidimensional arrays will not be found.
| Версія | Опис |
|---|---|
| 8.0.0 |
The key parameter now accepts
bool, float, int,
null, resource, and
string as arguments.
|
| 8.0.0 |
Passing an object to the array parameter is no longer supported.
|
| 7.4.0 |
Passing an object to the array parameter has been deprecated. Use property_exists() instead.
|
Приклад #1 array_key_exists() example
<?php
$searchArray = ['first' => 1, 'second' => 4];
var_dump(array_key_exists('first', $searchArray));
?>Поданий вище приклад виведе:
bool(true)
Приклад #2 array_key_exists() vs isset()
isset() does not return true for array keys
that correspond to a null value, while
array_key_exists() does.
<?php
$searchArray = ['first' => null, 'second' => 4];
var_dump(isset($searchArray['first']));
var_dump(array_key_exists('first', $searchArray));
?>Поданий вище приклад виведе:
bool(false) bool(true)