10

How can I run a loop in PHP to iterate alphabets from a-z?

Something like that:

for( $i ='a'; $i <= 'z'; $i++ ) {

    echo "<br>".$i;
 }
Narendrasingh Sisodia
  • 21,247
  • 6
  • 47
  • 54
Tahir
  • 483
  • 1
  • 4
  • 17
  • Possible duplicate of [Best way to list Alphabetical(A-Z) using PHP](http://stackoverflow.com/questions/2857246/best-way-to-list-alphabeticala-z-using-php) – Basheer Kharoti Nov 18 '15 at 07:36

2 Answers2

36

Simply use range function of PHP

foreach(range('a','z') as $v){
    echo "$v \n";
}
Narendrasingh Sisodia
  • 21,247
  • 6
  • 47
  • 54
5

You can use range:

<?php
foreach(range('a','z') as $letter) 
{ 
   echo "$letter<br/>"; 
}  

in addition you can store in array:

$alphas = range('a', 'z');
Thamilhan
  • 13,040
  • 5
  • 37
  • 59