Re: [PHP] Mystery foreach error

[email protected] (David Harkness)
Newsgroups php.general
Message-ID <CAO8qQL=PoR-1=kYHSJMOx2H=bRzWVkgHX_rArkTeQxhDFYOnnA@mail.gmail.com>
On Wed, Mar 13, 2013 at 4:44 PM, Angela Barone
<[email protected]>wrote:

> I ran across if(array_key_exists) and it seems to work.  How does that
> differ from if(isset($states[$state]))?


Hi Angela,

isset() will return false for an array key 'foo' mapped to a null value
whereas array_key_exists() will return true. The latter asks "Is this key
in the array?" whereas isset() adds "and is its value not null?" While
isset() is every-so-slightly faster, this should not be a concern. Use
whichever makes sense for the context here. Since you don't stick null
values into the array, I prefer the isset() form because the syntax reads
better to me.

Peace,
David
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.