RE: Letters loop

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

 



Hi,

I didn't even think PHP would do anything until I just tried it.

<?php
for ($i = "A"; $i <= "Z"; $i++){
	echo $i . "<br />";
}
?>

outputs:
A
B
C
....
X
Y
Z
AA
AB
....
AY
AX
....
YA
YB
....
YY
YZ

Why it continues after Z is not clear to me, and why it doesn't continue
until ZZ isn't either.

This works better and (more importantly) as expected:

<?php
$alfabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
foreach(preg_split("!!", $alfabet, -1, PREG_SPLIT_NO_EMPTY) as $char) {
	echo $char . "<br />";
}
?>

By the way, this code froze my browser:

<?php
for ($i = "A"; $i <= "z"; $i++){
	echo $i . "<br />";
}
?>


Jos

-----Original Message-----
From: MIGUEL ANTONIO GUIRAO AGUILAR
[mailto:miguel.guirao@xxxxxxxxxxxxxxx]
Sent: 26 May 2005 05:38
To: php-db@xxxxxxxxxxxxx
Subject:  Letters loop


Hi!!

I wanna a do a for loop with letters, Is this possible?

for ($i = 'A'; $i <= 'Z'; $i++){
// code
}

--------------------------
MIGUEL GUIRAO AGUILERA
Logistica R8 - Telcel
Tel: (999) 960.7994
Cel: 9931-60000

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

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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux