Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

array_key_exists(3) [php man page]

ARRAY_KEY_EXISTS(3)							 1						       ARRAY_KEY_EXISTS(3)

array_key_exists - Checks if the given key or index exists in the array

SYNOPSIS
bool array_key_exists (mixed $key, array $array) DESCRIPTION
array_key_exists(3) returns TRUE if the given $key is set in the array. $key can be any value possible for an array index. PARAMETERS
o $key - Value to check. o $array - An array with keys to check. RETURN VALUES
Returns TRUE on success or FALSE on failure. EXAMPLES
Example #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); ?> NOTES
Note 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 ALSO
isset(3), array_keys(3), in_array(3), property_exists(3). PHP Documentation Group ARRAY_KEY_EXISTS(3)

Check Out this Related Man Page

ARRAY_SEARCH(3) 							 1							   ARRAY_SEARCH(3)

array_search - Searches the array for a given value and returns the corresponding key if successful

SYNOPSIS
mixed array_search (mixed $needle, array $haystack, [bool $strict = false]) DESCRIPTION
Searches $haystack for $needle. PARAMETERS
o $needle - The searched value. Note If $needle is a string, the comparison is done in a case-sensitive manner. o $haystack - The array. o $strict - If the third parameter $strict is set to TRUE then the array_search(3) function will search for identical elements in the $haystack. This means it will also check the types of the $needle in the $haystack, and objects must be the same instance. RETURN VALUES
Returns the key for $needle if it is found in the array, FALSE otherwise. If $needle is found in $haystack more than once, the first matching key is returned. To return the keys for all matching values, use array_keys(3) with the optional $search_value parameter instead. Warning This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE. Please read the section on Booleans for more information. Use the === operator for testing the return value of this function. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.3.0 | | | | | | | As with all internal PHP functions as of 5.3.0, | | | array_search(3) returns NULL if invalid parame- | | | ters are passed to it. | | | | | 4.2.0 | | | | | | | Prior to PHP 4.2.0, array_search(3) returns NULL | | | on failure instead of FALSE. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 array_search(3) example <?php $array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red'); $key = array_search('green', $array); // $key = 2; $key = array_search('red', $array); // $key = 1; ?> SEE ALSO
array_keys(3), array_values(3), array_key_exists(3), in_array(3). PHP Documentation Group ARRAY_SEARCH(3)
Man Page