Query: array_key_exists
OS: php
Section: 3
Format: Original Unix Latex Style Formatted with HTML and a Horizontal Scroll Bar
ARRAY_KEY_EXISTS(3) 1 ARRAY_KEY_EXISTS(3) array_key_exists - Checks if the given key or index exists in the arraySYNOPSISbool array_key_exists (mixed $key, array $array)DESCRIPTIONarray_key_exists(3) returns TRUE if the given $key is set in the array. $key can be any value possible for an array index.PARAMETERSo $key - Value to check. o $array - An array with keys to check.RETURN VALUESReturns TRUE on success or FALSE on failure.EXAMPLESExample #1 array_key_exists(3) example <?php $search_array = array('first' => 1, 'second' => 4); if (array_key_exists('first', $search_array)) { echo "The 'first' element is in the array"; } ?> Example #2 array_key_exists(3) vs isset(3) isset(3) does not return TRUE for array keys that correspond to a NULL value, while array_key_exists(3) does. <?php $search_array = array('first' => null, 'second' => 4); // returns false isset($search_array['first']); // returns true array_key_exists('first', $search_array); ?>NOTESNote For backward compatibility, the following deprecated alias may be used: key_exists(3) Note For backward compatibility reasons, array_key_exists(3) will also return TRUE if $key is a property defined within an object given as $array. This behaviour should not be relied upon, and care should be taken to ensure that $array is an array. To check whether a property exists in an object, use property_exists(3).SEE ALSOisset(3), array_keys(3), in_array(3), property_exists(3). PHP Documentation Group ARRAY_KEY_EXISTS(3)