Print 'a' to 'z' via for loop

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
psaha
Forum Newbie
Posts: 16
Joined: Mon Oct 26, 2009 4:11 am

Print 'a' to 'z' via for loop

Post 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.
User avatar
Weiry
Forum Contributor
Posts: 323
Joined: Wed Sep 09, 2009 5:55 am
Location: Australia

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

Post 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
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

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

Post by Mark Baker »

Code: Select all

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