php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48545 Looping 'A' to 'Z' does not reach 'Z' and permutations are generated
Submitted: 2009-06-13 16:34 UTC Modified: 2009-06-15 08:47 UTC
From: robccsilva at gmail dot com Assigned:
Status: Not a bug Package: Variables related
PHP Version: 5.2.9 OS: Windows XP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: robccsilva at gmail dot com
New email:
PHP Version: OS:

 

 [2009-06-13 16:34 UTC] robccsilva at gmail dot com
Description:
------------
Trying to write:
ABCDEFGHIJKLMNOPQRSTUVWXYZ

1.
ABCDEFGHIJKLMNOPQRSTUVWXY

2.
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAF...SYTYUYVYWYXYYYZ

3.
ABC...ZZY



Reproduce code:
---------------
<html>
<body>
<?php

echo "Hello World!<br /><br />\r\n";

echo "On this test case I will write the letters A-Z the easy way!<br />\r\n";
echo "If you the result of each test, you the man!<br />\r\n";
echo "<br /><br />\r\n";

echo "On this small test you might 'crash' your browser, run at your risk! ;)<br />\r\n";
echo "<br /><br />\r\n";

echo "1. I think as a noob, so the first script should get me to the 'Z' as follows:<br />\r\n";
for ($letter = 'A'; $letter < 'Z'; $letter++) { echo $letter; }

echo "<br /><br />\r\n";

echo "2. As a noobster, I want to reach 'Z' as follows:<br />\r\n";
for ($letter = 'A'; $letter <= 'Z'; $letter++) { echo $letter; }

echo "<br /><br />\r\n";

echo "3. Being a major noob, decided to reach 'Z' as follows:<br />\r\n";
for ($letter = 'A'; $letter < 'Z'+1; $letter++) { echo $letter; }


?>
</body>
</html>

Expected result:
----------------
Write ABCDEFGHIJKLMNOPQRSTUVWXYZ


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-06-15 08:47 UTC] jani@php.net
There are several user comments about this on page:
http://www.php.net/manual/en/control-structures.for.php

Z being "less" than AA causes this "unexpected" behaviour which is quite 
expected. 

You could also do it like this:

foreach(range('A', 'Z') as $letter)
  echo $letter;


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 15 23:01:33 2025 UTC