RE: [PHP] Re: possible bug (string equality to zero)?

From: Date: Thu, 11 Aug 2005 17:16:55 +0000
Subject: RE: [PHP] Re: possible bug (string equality to zero)?
Groups: php.general 
Request: Send a blank email to php-general+get-220454@lists.php.net to get a copy of this message
[snip] But the var isn't empty. $a[] = 'blah'; $a[] = 'blah'; $a['assoc'] = 'array'; foreach ($a as $k => $v) if ($k == 'assoc') # do something The 'if' statement is incorrectly executing when $k is 0. I find it strange that 0 == any string. The way I see it, 0 is false. false == 'a string' should not be true. [/snip] I changed this sample to the following; <?php $a[] = 'blah'; $a[] = 'blah'; $a['assoc'] = 'array'; print_r($a); foreach ($a as $k => $v){ if ($k == 'assoc'){ echo $v . "\n"; } } ?> Andf the output was; Array ( [0] => blah [1] => blah [assoc] => array ) blah array Does it begin to make more sense now?

« previous php.general (#220454) next »