Alphabetical "for" and "foreach" loops in PHP
By combining a for loop with PHP's chr() function you can create a loop that will run through each letter of the alphabet:
<?php
for ($i=65; $i <= 90; $i++)
{
echo chr($i);
}
?>
An easier way to loop through each letter of the alphabet (or each value of any range therein), is to use PHP's range() function in combination with a foreach loop:
<?php
foreach (range('a', 'z') as $i)
{
echo $i;
}
?>
You can even use the range() function to loop through the letters in reverse alphabetical order:
<?php
foreach (range('g', 'b') as $i)
{
echo $i;
}
?>