List Alphabetical Characters A-Z with PHP

July 1st, 2013 - Posted by Steve Marks to PHP, Web Development.

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;
}
Tags: ,
This entry was posted on Monday, July 1st, 2013 at 8:59 pm by +Steve Marks and is filed under PHP, Web Development. You can follow any responses to this entry through the RSS 2.0 feed.
Comments...

Fear not, we won't publish this

Comments (0)

No comments have been left yet. Be the first