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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 21:01:33 2024 UTC