RE: [PHP-DB] Letters loop
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:[EMAIL PROTECTED] 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-6 -- 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
Re: [PHP-DB] Letters loop
MIGUEL ANTONIO GUIRAO AGUILAR wrote: 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-6 No, but there are multiple ways this can be done. You could create a string, loop through it's length, then access the $i character in the string. $sAlpha = 'ABCDEF...XYZ'; for($i=0;$i26;++$i) { $sLetter = $sAlpha{$i}; // code } or maybe loop through an array of the letters foreach(array('A','B','C',...,'X','Y','Z') as $sLetter) { // code } or even use the ASCII values for($i=65;$i91;++$i) { $sLetter = chr($i); // code } I tend to prefer the first method, but, depending on your situation, one of the others might work better. Chris -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Letters loop
hi Miguel I wanna a do a for loop with letters, Is this possible? for ($i = 'A'; $i = 'Z'; $i++){ // code } you can, but it doesn't do what you think it should do. Apparently it gets to Z, restarts with AA, AB, AC etc and continues like that until it hits YZ. feck knows why :-/ hth (a bit) Rob -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Letters loop
Chris wrote: You could create a string, loop through it's length, then access the $i character in the string. $sAlpha = 'ABCDEF...XYZ'; for($i=0;$i26;++$i) { $sLetter = $sAlpha{$i}; // code } range() is a powerful function for creating such strings. You don't need to loop. -Rasmus -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Letters loop
MIGUEL ANTONIO GUIRAO AGUILAR wrote: Hi!! I wanna a do a for loop with letters, Is this possible? for ($i = 'A'; $i = 'Z'; $i++){ // code } try it. php -r ' for ($i = a; $i z; $i++){ echo $i,.; } echo z;' -- MIGUEL GUIRAO AGUILERA Logistica R8 - Telcel Tel: (999) 960.7994 Cel: 9931-6 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Letters loop
try for ($i =ord( 'A'); $i = ord('Z'); $i++){ // code } bastien From: MIGUEL ANTONIO GUIRAO AGUILAR [EMAIL PROTECTED] To: php-db@lists.php.net Subject: [PHP-DB] Letters loop Date: Wed, 25 May 2005 20:37:47 -0700 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-6 -- 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
RE: [PHP-DB] Letters loop
Thanks!! I think the ord() function should receive an integer as a parameter and it returns it's corresponding character. But it will work!!! -Original Message- From: Bastien Koert [mailto:[EMAIL PROTECTED] Sent: Jueves, 26 de Mayo de 2005 08:28 a.m. To: [EMAIL PROTECTED]; php-db@lists.php.net Subject: RE: [PHP-DB] Letters loop try for ($i =ord( 'A'); $i = ord('Z'); $i++){ // code } bastien From: MIGUEL ANTONIO GUIRAO AGUILAR [EMAIL PROTECTED] To: php-db@lists.php.net Subject: [PHP-DB] Letters loop Date: Wed, 25 May 2005 20:37:47 -0700 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-6 -- 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
RE: [PHP-DB] Letters loop
nope chr ( int ascii ) takes the integer ord ( string string ) takes the string bastien From: Miguel Guirao [EMAIL PROTECTED] To: php-db@lists.php.net Subject: RE: [PHP-DB] Letters loop Date: Thu, 26 May 2005 09:22:56 -0500 Thanks!! I think the ord() function should receive an integer as a parameter and it returns it's corresponding character. But it will work!!! -Original Message- From: Bastien Koert [mailto:[EMAIL PROTECTED] Sent: Jueves, 26 de Mayo de 2005 08:28 a.m. To: [EMAIL PROTECTED]; php-db@lists.php.net Subject: RE: [PHP-DB] Letters loop try for ($i =ord( 'A'); $i = ord('Z'); $i++){ // code } bastien From: MIGUEL ANTONIO GUIRAO AGUILAR [EMAIL PROTECTED] To: php-db@lists.php.net Subject: [PHP-DB] Letters loop Date: Wed, 25 May 2005 20:37:47 -0700 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-6 -- 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 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Letters loop
Absolutely nothing wrong with that solution. But here is an alternative just for fun: for($letters = range('A','Z'), $i=0; isset($letters{$i}); $i++) echo $letters{$i}. ; -Rasmus Miguel Guirao wrote: Thanks!! I think the ord() function should receive an integer as a parameter and it returns it's corresponding character. But it will work!!! -Original Message- From: Bastien Koert [mailto:[EMAIL PROTECTED] Sent: Jueves, 26 de Mayo de 2005 08:28 a.m. To: [EMAIL PROTECTED]; php-db@lists.php.net Subject: RE: [PHP-DB] Letters loop try for ($i =ord( 'A'); $i = ord('Z'); $i++){ // code } bastien From: MIGUEL ANTONIO GUIRAO AGUILAR [EMAIL PROTECTED] To: php-db@lists.php.net Subject: [PHP-DB] Letters loop Date: Wed, 25 May 2005 20:37:47 -0700 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-6 -- 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