Is there a way to get all alphabetic chars (A-Z) in an array in PHP so I can loop through them and display them?
+2
A:
$alphabet = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z')
funny but usable
Click Upvote
2009-01-12 04:44:54
A:
<?php
$array = Array();
for( $i = 65; $i < 91; $i++){
$array[] = chr($i);
}
foreach( $array as $k => $v){
echo "$k $v \n";
}
?>
$ php loop.php
0 A
1 B
2 C
3 D
4 E
5 F
6 G
7 H
...
Aaron Maenpaa
2009-01-10 23:05:23
You may of been using JavaScript a while because Array() should really be array(). Or, in JS, [] :)
alex
2010-01-19 06:09:03
+3
A:
To get both upper and lower case merge the two ranges:
$alphas = array_merge(range('A', 'Z'), range('a', 'z'));
PEZ
2009-01-11 16:04:39
+3
A:
Another way:
$c = 'A';
$chars = array($c);
while ($c < 'Z') $chars[] = ++$c;
Gumbo
2009-01-11 16:17:10