php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #7385 'letter counting' bug when counting a-z
Submitted: 2000-10-21 21:13 UTC Modified: 2000-10-22 14:56 UTC
From: delme at jumeaux dot bc dot ca Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0.3pl1, 4.0.2 OS: Linux 2.2 and win32
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: delme at jumeaux dot bc dot ca
New email:
PHP Version: OS:

 

 [2000-10-21 21:13 UTC] delme at jumeaux dot bc dot ca
for ($i = 'A'; $i <= 'Z'; $i++) {
    print $i. '<br>';
}

the above code *should* produce 26 letters, but instead it counts all the way from A to YZ.

A to ZZ counts from A to ZYZ, and so on.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-10-22 11:20 UTC] lyric@php.net
Applying ++ to a string essentially treats it like a base-26 number. It goes from 'a,b,c... y,z,aa,ab,ac...' etc. 

Try something like this. Maybe some else has a tidier way?

  for ( $i='A'; $i!='AA'; $i++ )
    print $i. '<br>';

 [2000-10-22 14:56 UTC] delme at jumeaux dot bc dot ca
i assume your point is that <= does not operate on letters in the same way; it's a string comparison operator.  i should have seen this, i suppose.

it's too late now, but perhaps php should have been developed more along the lines of perl, with separate operators for string functions... then mathematical operators could treat letters as base 26 numbers, and string operators could do alphabetical comparisons.

this special overloading of ++ is misleading.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 03 11:01:32 2024 UTC