List Alphabetical Characters A-Z with PHP
I wanted to share a really simple way to get all the characters from the alphabet so that they can be easily iterated through. I’ll be using the PHP range() function which, aside from getting characters from the alphabet, can also be used to obtain other ranges, such as numbers.
Let’s begin by looking at how we can get, and loop through, the letters in the alphabet:
- $letters = range('A', 'Z');
- foreach ($letters as $letter)
- {
- echo $letter;
- }
The above would list all the characters from A, through to Z. Note that this would only do the uppercase letters. We could do a similar exercise for lowercase characters in a similar way like so:
- $letters = range('a', 'z');
- foreach ($letters as $letter)
- {
- echo $letter;
- }
0 comments:
Post a Comment