Re: Letters loop

From: Date: Thu, 26 May 2005 06:15:04 +0000
Subject: Re: Letters loop
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-39552@lists.php.net to get a copy of this message
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-60000 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;$i<26;++$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;$i<91;++$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

« previous php.db (#39552) next »