Re: Looping from A to Z

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Good afternoon. I'm having trouble getting PHP to loop from A through Z. Here is what I tried, coming from a C background:

for ($l = "A"; $l <= "Z"; $l++)
   echo $l;

// Returns A, B, C, ..., X, Y, Z, AA, AB, AC, AD, AE, ... YX, YY, YZ. (26 * 26 results!)

Interestingly, if I make it a "less than" operation instead of "less than or equal to", it works correctly (except for the Z):

for ($l = "A"; $l < "Z"; $l++)
   echo $l;

// Returns A, B, C, ..., W, X, Y  (25 results)

Anyone know why PHP would do that?

Nope... but try...

for ( $l = ord("A"); $l <= ord("Z"); $l++ )
	echo $l;

Also maybe check out the range() function.

-philip

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux