Posted By

plesh on 07/12/11


Tagged

php foreach chr


Versions (?)

Loop through Alphabet with PHP


 / Published in: PHP
 

URL: http://www.apashley.co.uk/snippets/38/Loop-Through-The-Alphabet-With-Php.html

Loops through ASCII characters to display alphabet, useful for alphabetic filtering links.

eg: A | B | C | D ...

  1. // Loop through ASCII characters until reaching 90
  2. for ($i=65; $i<=90; $i++) {
  3.  
  4. // store the character
  5. $letter = chr($i);
  6.  
  7. // build alphabetical link
  8. $alphabet .= '<a title="filter results by letter '.$letter.'" href="/business/'.$letter.'"> ';
  9. $alphabet .= $letter;
  10. $alphabet .= '</a> | ';
  11. }
  12.  
  13. // print links
  14. echo $alphabet;

Report this snippet  

You need to login to post a comment.