Re: What's wrong with this code??

From: Date: Fri, 30 May 2003 23:39:24 +0000
Subject: Re: What's wrong with this code??
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-149618@lists.php.net to get a copy of this message
At 01:08 30.04.2003, Beauford said: --------------------[snip]-------------------- >if ($mo == 06 and $dy > 01 and $dy < 09) { $wd = "8"; } >if ($mo == 06 and $dy > 08) { $wd = "9"; } --------------------[snip]-------------------- The problem is your notation. If you had written if ($mo == 6 and $dy > 1 and $dy < 9) { $wd = "8"; } if ($mo == 6 and $dy > 8) { $wd = "9"; } your logic would still look a bit clumsy but work as you intend. Why? Prefixing a number with a zero makes the intepreter believe you're using octal numbers. Oczal numbers range from 00 to 07, the decimal number 8 would be 010 in octal notation. Your code, translated in decimal for better understanding, is seen by the compiler as if ($mo == 6 and $dy > 1 and $dy < 2) { $wd = "8"; } if ($mo == 6 and $dy > 0) { $wd = "9"; } (08 => decimal 0, 09 => decimal 1). In this case your last statement will trigger for _any_ day in June. -- >O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/

« previous php.general (#149618) next »