easiest way to create an array of alphabets - range
by rajesh[ Edit ] 2010-01-02 15:16:49
Th easiest way to create an alphabets is using range() function
// to get a array of characters from a to f
$a = range('a','f');
print_r($a);
// to get a array of characters from d to h
$b = range('d','h');
print_r($b);
?>
Result:
Array ( [0] => a [1] => b [2] => c [3] => d [4] => e [5] => f )
Array ( [0] => d [1] => e [2] => f [3] => g [4] => h )
Range can also be used to get an array of numbers with a increment range between each number.
Say, if I want numbers 10,20,30,40,50,60 in an array I can use range as
$a = range(0,60,10);
print_r($a);
?>
Result:
Array ( [0] => 10 [1] => 20 [2] => 30 [3] => 40 [4] => 50 [5] => 60 )