8

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
  • 20,667
  • 5
  • 43
  • 53
Tahir
  • 423
  • 1
  • 4
  • 16
  • 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

32

Simply use range function of PHP

foreach(range('a','z') as $v){
    echo "$v \n";
}
Narendrasingh Sisodia
  • 20,667
  • 5
  • 43
  • 53
4

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
  • 12,752
  • 5
  • 35
  • 59