|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-11-09 11:07 UTC] thomas dot keller at inatec dot com
Description:
------------
Configure command:
'./configure' '--prefix=/usr/local/php' '--with-apxs2=/home/apache2/apache-2.0.52/bin/apxs' '--enable-versioning' '--with-mysql=/usr/local/mysql' '--with-gd' '--with-zlib'
I use the following code snippet to print out an array
of chars in alphabetic order. If I have the condition
$i < 'Z' (so only until 'Y'), everything works fine,
for the condition(s) $i <= 'Z' or $i < ('A' + 26)
PHP produces wrong results.
I could reproduce the error on a Redhat 9 system with PHP 4.3.4.
Reproduce code:
---------------
$letters = array();
for ($i='A'; $i<='Z'; $i++) print $i;
Expected result:
----------------
ABCDEFGHIJKLMNOPQRSTUVWXYZ
(26 ^ 1 letters)
Actual result:
--------------
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABAC .. YZ
(26 ^ 2 letters)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 05 08:00:02 2025 UTC |
Hrm... I thought of 'Z' not as a string, but as a single character. In other programming languages (C/C++, Java) a char is a signed BYTE, thus can be used as replacement for integer values. So I expect I need to write for ($i=ord('A');$i<=ord('Z'); $i++) print chr(i); to get my desired output? Since I don't know a PHP shorthand for Perl's foreach ('A' .. 'Z') print $_; Thanks for clearing that up.