Page 1 of 1

Print 'a' to 'z' via for loop

Posted: Mon Oct 26, 2009 4:24 am
by psaha
A very simple problem..
How Can I print a to z NOT a to y ?
It is a part of a code where

Code: Select all

$alpha= 'a';
for($alpha='a';$alpha!='z';$alpha++)
{
echo $alpha.'  ';
}
 
Output: a b c d e f g h i j k l m n o p q r s t u v w x y
$alpha!='z' have the problem..$alpha<='z' creates problem.
please help me about the for loop condition.

Re: Print 'a' to 'z' via for loop

Posted: Mon Oct 26, 2009 4:40 am
by Weiry
you could try using the chr() function.

Code: Select all

 
for($i=97;$i<=122;$i++;){
   print chr($i)." ";
}
 
Where $i is the location in the ASCII table of the letters you want.
ASCII Table

Re: Print 'a' to 'z' via for loop

Posted: Mon Oct 26, 2009 4:49 am
by Mark Baker

Code: Select all

$alpha='a';
do {
    echo $alpha++.'  ';
} while ($alpha != 'aa');