PHP

PHP – Writing An A to Z Loop

January 26, 2009

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);
}

Simple!

Only registered users can comment.

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

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.