Re: What's wrong with this code??
| From: | Beauford | Date: | Sat, 31 May 2003 00:02:22 +0000 |
| Subject: | Re: What's wrong with this code?? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-149619@lists.php.net to get a copy of this message | ||
I figured that out after I sent the email. The reason I used the 0 in the
first place was that I was having all sorts of problems with it - and it
seemed to work fine for 01 to 05 so I just continued on with it - not even
thinking about it.
Your right though, the code is awkward - but I couldn't think of any other
way of doing it.
Any suggestions?
Thanks
----- Original Message -----
From: "Ernest E Vogelsinger" <ernest@vogelsinger.at>
To: "Beauford" <beauford.2005@rogers.com>
Cc: "PHP General" <php-general@lists.php.net>
Sent: Friday, May 30, 2003 7:39 PM
Subject: Re: [PHP] What's wrong with this code??
> 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/
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>