Page 1 of 1

alphabets generation

Posted: Sat Jun 30, 2007 6:45 am
by itsmani1
I want to generate alphabets form a-z, Is there any php function for this.

Posted: Sat Jun 30, 2007 7:19 am
by feyd
What research have you done?

Posted: Sat Jun 30, 2007 7:33 am
by miro_igov
how about for() loop ? Especially

Code: Select all

for($i='a';$i<='z';$i++) echo $i."<br>";

Posted: Sat Jun 30, 2007 8:58 am
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);
}

Posted: Sat Jun 30, 2007 9:00 am
by Benjamin

Code: Select all

range('a', 'z');

Posted: Sat Jun 30, 2007 9:06 am
by Weirdan
d11wtq wrote: Does that work?
It does.

Posted: Sat Jun 30, 2007 9:53 am
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>';
?>

Posted: Sat Jun 30, 2007 10:48 am
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 ;)

Posted: Sat Jun 30, 2007 10:56 am
by feyd
range() is superior in this case. ;)