RE: [PHP] Re: Avoiding NOTICEs on Array References
| From: | Michael Sims | Date: | Thu, 27 Jan 2005 12:36:59 +0000 |
| Subject: | RE: [PHP] Re: Avoiding NOTICEs on Array References | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-207469@lists.php.net to get a copy of this message | ||
Burhan Khalid wrote:
> Michael Sims wrote:
>>> trlists@clayst.com wrote:
>>>
>>>> If one must check the value and not just the existence of the
>>>> checkbox entry, or for other uses, e.g. where a flag may or may not
>>>> be present, one is saddled with clumsy constructs like:
>>>>
>>>> if (($isset($array['index']) && ($array['index'] ==
>>>> 1)) ...
>
> I'm surprised that no one mentioned
>
> if (array_key_exists("index",$array)) { /* .. */ }
Because we're talking about avoiding clumsiness, and:
if (array_key_exists('index', $array) && $array['index'] == 1) ...
is MORE verbose (and arguably clumsier) than
if (isset($array['index']) && $array['index'] == 1) ...
which for the purposes of this discussion is equivalent.
(And yes, I realize that in the case of a checkbox the mere test for key
existence is sufficient, but I like to be consistent in these types of
constructs despite the input type...)