Re: Mystery foreach error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Mar 13, 2013 at 4:44 PM, Angela Barone
<angela@xxxxxxxxxxxxxxxxxxxx>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

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux