Re: Mystery foreach error

From: Date: Thu, 14 Mar 2013 00:02:32 +0000
Subject: Re: Mystery foreach error
References: 1 2 3 4 5 6 7 8 9  Groups: php.general 
Request: Send a blank email to php-general+get-320527@lists.php.net to get a copy of this message
On Wed, Mar 13, 2013 at 4:44 PM, Angela Barone <angela@italian-getaways.com>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

« previous php.general (#320527) next »