Re: print a to z
| From: | Lars Torben Wilson | Date: | Fri, 16 Jan 2009 06:44:23 +0000 |
| Subject: | Re: print a to z | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-286485@lists.php.net to get a copy of this message | ||
2009/1/15 Leon du Plessis <leon@dsgnit.com>:
> I used that notation before, and it did not work 100%.
> Adapt as follows:
>
> for ($i = 'a'; $i <= 'z'; $i++)
> if ($i == "aa") break; else echo $i;
It's weird, but true--the simple '<=' breaks the loop.
However, in the above example, you don't need the 'else'; the 'break'
ensures that the 'echo $i'; will not execute.
You can step around the the problem more elegantly:
for ($i = 'a'; $i !== 'aa'; $i++) {
echo $i;
}
Regards,
Torben
> -----Original Message-----
> From: Paul M Foster [mailto:paulf@quillandmouse.com]
> Sent: 16 January 2009 07:55 AM
> To: php-general@lists.php.net
> Subject: Re: [PHP] print a to z
>
> On Thu, Jan 15, 2009 at 08:32:14PM -0800, paragasu wrote:
>
>> i have this cute little problem. i want to print a to z for site
> navigation
>> my first attempt work fine
>>
>> for($i = '65'; $i < '91'; ++$i)
>> echo chr($i);
>>
>> but someone point me a more interesting solutions
>>
>> for($i = 'a'; $i < 'z'; ++$i)
>> echo $i
>>
>> the only problem with the 2nd solutions is it only print up to Y without
> z.
>> so how to print up to z with the 2nd solutions? because it turn out
>> that you cant to something
>> like for($i = 'a'; $i <= 'z'; ++$i)..
>
> for ($i = 'a'; $i <= 'z'; $i++)
> echo $i;
>
> Paul
>
> --
> Paul M. Foster