Re: [PHP] Mystery foreach error

2013-03-13 Thread Angela Barone
On Mar 13, 2013, at 5:02 PM, David Harkness wrote: > 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-

Re: [PHP] Mystery foreach error

2013-03-13 Thread Sebastian Krebs
2013/3/14 David Harkness > > On Wed, Mar 13, 2013 at 5:10 PM, Sebastian Krebs wrote: > >> Because 'null' is the representation of "nothing" array_key_exists() and >> isset() can be treated as semantically equivalent. > > > As I said, these functions return different results for null values. It >

Re: [PHP] Mystery foreach error

2013-03-13 Thread David Harkness
On Wed, Mar 13, 2013 at 5:10 PM, Sebastian Krebs wrote: > Because 'null' is the representation of "nothing" array_key_exists() and > isset() can be treated as semantically equivalent. As I said, these functions return different results for null values. It won't matter for Angela since she isn't

Re: [PHP] Mystery foreach error

2013-03-13 Thread Sebastian Krebs
2013/3/14 David Harkness > On Wed, Mar 13, 2013 at 4:44 PM, Angela Barone > 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

Re: [PHP] Mystery foreach error

2013-03-13 Thread David Harkness
On Wed, Mar 13, 2013 at 4:44 PM, Angela Barone 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

Re: [PHP] Mystery foreach error

2013-03-13 Thread Angela Barone
On Mar 13, 2013, at 4:24 PM, Matijn Woudt wrote: > That wouldn't work, in_array checks the values, and your states are in the > keys. Use: > if(isset($states[$state])) Hi Matijn, Before I received your email, I ran across if(array_key_exists) and it seems to work. How does that differ

Re: [PHP] Mystery foreach error

2013-03-13 Thread Matijn Woudt
On Thu, Mar 14, 2013 at 12:18 AM, Angela Barone wrote: > On Mar 13, 2013, at 9:07 AM, Jim Giner wrote: > > Why not just check if the $state exists as a key of the array $states > before doing this? > > Jim, > > Are you thinking about the in_array function? > > Angela That wouldn't work,

Re: [PHP] Mystery foreach error

2013-03-13 Thread Angela Barone
On Mar 13, 2013, at 9:07 AM, Jim Giner wrote: > Why not just check if the $state exists as a key of the array $states before > doing this? Jim, Are you thinking about the in_array function? Angela

Re: [PHP] Mystery foreach error

2013-03-13 Thread Matijn Woudt
On Wed, Mar 13, 2013 at 5:07 PM, Jim Giner wrote: > On 3/12/2013 9:04 PM, Angela Barone wrote: > >> On Mar 12, 2013, at 5:16 PM, David Robley wrote: >> >>> Presumably there is a fixed list of State - those are US states? - >>> >> >> so why not provide a drop down list of the possible choices? >>>

Re: [PHP] Mystery foreach error

2013-03-13 Thread Jim Giner
On 3/12/2013 9:04 PM, Angela Barone wrote: On Mar 12, 2013, at 5:16 PM, David Robley wrote: Presumably there is a fixed list of State - those are US states? - so why not provide a drop down list of the possible choices? There is, but the problem must have been that if someone didn't

Re: [PHP] Mystery foreach error

2013-03-12 Thread Angela Barone
On Mar 12, 2013, at 5:16 PM, David Robley wrote: > Presumably there is a fixed list of State - those are US states? - > so why not provide a drop down list of the possible choices? There is, but the problem must have been that if someone didn't select a State, $state was blank. I've sin

Re: [PHP] Mystery foreach error

2013-03-12 Thread David Robley
Angela Barone wrote: > I think I figured it out. > > $states = array( > 'AL' => array( '350','351','352','353', ), > 'AK' => array( '995','996','997','998','999', ), > 'AZ' => array( '850','851','852','853','854', ), > 'WI' => array( '530','531','532', ), > 'WY' => array( '82

Re: [PHP] Mystery foreach error

2013-03-12 Thread Angela Barone
I think I figured it out. array( '350','351','352','353', ), 'AK' => array( '995','996','997','998','999', ), 'AZ' => array( '850','851','852','853','854', ), 'WI' => array( '530','531','532', ), 'WY' => array( '820','821','822','823','824', ), ); $zip = 35261; $state =

Re: [PHP] Mystery foreach error

2013-03-12 Thread Jim Giner
$states = array( 'AL' => array( '350','351','352','353', ), 'AK' => array( '995','996','997','998','999', ), 'AZ' => array( '850','851','852','853','854', ), ... 'WI' => array( '530','531','532', ), 'WY' => array( '820','821','822','823','824', ), ); ?> Seei

Re: [PHP] Mystery foreach error

2013-03-12 Thread Angela Barone
On Mar 12, 2013, at 2:26 PM, Marco Behnke wrote: > what is in $states? > Looks like $states[$state] is not an array. Here's a sample: array( '350','351','352','353', ), 'AK' => array( '995','996','997','998','999', ), 'AZ' => array( '850','851','852','853','854', ), ...

Re: [PHP] Mystery foreach error

2013-03-12 Thread Marco Behnke
Am 12.03.13 20:45, schrieb Angela Barone: > I've been getting the following error for awhile now, but I can't > figure out why it's happening: > > Invalid argument supplied for foreach() in ... sample.php on line 377 > > Here's that portion of code: > > include("states_zipcodes.php");