Re: BUG?: for loop using chars
| From: | Kevin Stone | Date: | Thu, 16 May 2002 22:45:52 +0000 |
| Subject: | Re: BUG?: for loop using chars | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-97982@lists.php.net to get a copy of this message | ||
No, no bug. I believe you would end up with something like that if the for
loop is evaluating the letters numerically (either as ASCII values or some
other value). The examples below would be the proper way of printing a
range of letters...
$letters = range('a', 'z');
for ($i=0; $i<count($letters); $i++)
{
echo $letters[$i];
}
.. or..
foreach(range('a', 'z') as $letter)
{
echo $letter;
}
Hope this helps.
-Kevin
----- Original Message -----
From: "Erich Reimberg N" <ereimber@multinet.cl>
To: <php-general@lists.php.net>
Sent: Thursday, May 16, 2002 11:27 AM
Subject: [PHP] BUG?: for loop using chars
> Hello,
>
> I'm trying to generate this list of letters A..Z, using this
>
> for ($l='A'; $l<='Z'; $l++)
> echo $l."-";
>
> And it doesn't work. It generates the output included at the end of
> this message (I used .... to be shorter)
>
> But this works
> for ($l='A'; $l<='Y'; $l++)
> echo $l."-";
> generating the expected output.
>
> IS this a bug in PHP?
>
> Any help? Please, if you can, Cc to my email: ereimber@multinet.cl
>
> TIA,
> Erich
>
> ---
> Wrong output:
> A-B-C-D-E-F-G-H-I-J-K-L-M-N-O-P-Q-R-S-T-U-V-W-X-Y-Z-AA-AB-AC-AD-AE-AF-
> AG-AH-AI........-YV-YW-YX-YY-YZ-
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>