PHP – Writing An A to Z Loop

I was recently developing a PHP scraping script to extract the contents of a couple of websites and I wanted to find a quick way to run through a loop for each letter of the alphabet.  I figured since PHP was so versatile there had to be a quick and easy way, so I did a bit of thinking and came up with this:

for($alpha = 65; $alpha <= 90; $alpha++) {
      echo chr($alpha);


Tags: , ,

  • StumbleUpon
  • Reddit
  • Twitter
  • RSS

7 Responses to “PHP – Writing An A to Z Loop”

  1. stesch says:

    You should make a PEAR package out of this.

  2. acct_rdt says:

    It’s a good thing PHP is so versatile!

  3. Dhanunjaya Rao says:

    It’s a good thing PHP is so useful!

  4. raito says:


    for ($a = ‘a’; $a !== ‘aa’; $a++)
    print($a . ”);

  5. FettesPS says:

    @raito – That’s another interesting approach I’ve not seen before. Thanks for sharing 🙂 It’s amazing how flexible PHP can be at times.

  6. WesM says:

    foreach (range(‘A’, ‘Z’) as $letter)
    echo $letter;

Leave a Reply