Re: A very strange loop!
| From: | Darren Whitlen | Date: | Mon, 09 Jul 2007 08:14:31 +0000 |
| Subject: | Re: A very strange loop! | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-258483@lists.php.net to get a copy of this message | ||
Xell Zhang wrote:
Hello all, I met a very strange problem today. Take a look at the codes below: for ($i = 'A'; $i < 'Z'; $i++) { echo $i . ' '; } If you think the output is A-Z, please run it on your server and try. Who can tell me why the result is not A-Z?The result doesnt include the 'Z', as if $i = 'Z', then $i < 'Z' would return false, so would leave the loop there before echoing it out. PHP seems to increment the alphabet by A, B, C.... Y, Z, AA, AB, AC.... So you could use: for ($i = 'A'; $i != 'AA'; $i++) { echo $i . ' '; } Using $i < 'AA' doesn't seem to work either, which I find a bit odd. Hope that helps, Darren