For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > May 2005 > RE: [PHP-DB] Letters loop









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author RE: [PHP-DB] Letters loop
Juffermans, Jos

2005-05-27, 3:56 pm

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@mail.telcel.com]
Sent: 26 May 2005 05:38
To: php-db@lists.php.net
Subject: [PHP-DB] 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
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com