#6599 [Com]: strange behaviour in for loops with strings++
| From: | martin at tack dot se | Date: | Tue, 08 Apr 2003 13:48:12 +0000 |
| Subject: | #6599 [Com]: strange behaviour in for loops with strings++ | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-37352@lists.php.net to get a copy of this message | ||
ID: 6599
Comment by: martin at tack dot se
Reported By: adobernig at netway dot at
Status: Closed
Bug Type: Strings related
Operating System: LINUX RH 6.1
PHP Version: 4.0.2
New Comment:
I just hit this aswell. I personally dislike the behaviour. However,
rewrite your loop like this to get the expected behaviour:
for ($i=ord('A'); $i<=ord('Z'); $i++)
echo chr($i)."<br>";
Previous Comments:
------------------------------------------------------------------------
[2000-09-20 01:46:51] stas@php.net
This is an intended behaviour, ++ on strings is "magical" in PHP, like
in Perl, so "Z"++ is "AA".
------------------------------------------------------------------------
[2000-09-07 08:53:53] adobernig at netway dot at
for ($char="A";$char<="Z";$char++)
{
echo "$char - ";
}
the last char displayed by this script
is not "Z" but "YZ"
with ever other letter it works as it should
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=6599&edit=1