Printing the alphabet in PHP
I was wondering of there was an smarter way to print the whole alphabet in PHP than just creating an array containing all off the letters by my self.
I present to you, the range() function.
<?php
foreach(range('a', 'z') as $letter) {
echo $letter;
}
?>This function will also work with numbers. This will print all the numbers from 1 to 12.
<?php
foreach(range(0, 12) as $number) {
echo $number;
}
?>And if you are smart, and run PHP 5, you can even print every tenth number (0,10,20,30...)
<?php
foreach(range(0, 100, 10) as $number) {
echo $number;
}
?> 