alphabets generation

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
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

alphabets generation

Post by itsmani1 »

I want to generate alphabets form a-z, Is there any php function for this.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

What research have you done?
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post by miro_igov »

how about for() loop ? Especially

Code: Select all

for($i='a';$i<='z';$i++) echo $i."<br>";
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

miro_igov wrote:how about for() loop ? Especially

Code: Select all

for($i='a';$i<='z';$i++) echo $i."<br>";
Does that work? 8O I'd have done this:

Code: Select all

<?php

for ($i = ord("a"); $i <= ord("z"); $i++) {
  echo chr($i);
}
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Code: Select all

range('a', 'z');
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

d11wtq wrote: Does that work?
It does.
User avatar
WaldoMonster
Forum Contributor
Posts: 225
Joined: Mon Apr 19, 2004 6:19 pm
Contact:

Post by WaldoMonster »

Weirdan wrote:
d11wtq wrote: Does that work?
It does.
On my system it doesn't work (php 4).
The list goes from a - yz

I use it this way:

Code: Select all

<?php
for($i = 'a'; $i != 'aa'; $i++)
    echo $i . '<br>';
?>
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post by miro_igov »

Does that work? 8O I'd have done this:

Code: Select all

<?php

for ($i = ord("a"); $i <= ord("z"); $i++) {
  echo chr($i);
}
[/quote]

d11wtq, the low number of posts in this forum does not mean a newbie ;)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

range() is superior in this case. ;)
Post Reply