4.10.1. ProblemYou want to know if an array contains a certain key. 4.10.2. SolutionUse array_key_exists( ) to check for a key no matter what the associated value is: if (array_key_exists('key', $array)) { /* there is a value for $array['key'] */ } Use isset( ) to find a key whose associated value is anything but null: if (isset($array['key'])) { /* there is a non-null value for 'key' in $array */ } 4.10.3. DiscussionThe array_key_exists( ) function completely ignores array values'it just reports whether there is an element in the array with a particular key. isset( ), however, behaves the same way on array keys as it does with other variables. A null value causes isset( ) to return false. See the Introduction to Chapter 5 for more information about the truth value of variables. 4.10.4. See AlsoDocumentation on isset( ) at http://www.php.net/isset and on array_key_exists( ) at http://www.php.net/array_key_exists. |