Create Array containg A-Z list

Small, short code snippets that other people may find useful. Do you have a good regex that you would like to share? Share it! Even better, the code can be commented on, and improved.

Moderator: General Moderators

Post Reply
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Create Array containg A-Z list

Post by JayBird »

Saves typing all th letters yourself

Code: Select all

for ($i = 65; $i < 91; $i++) { 
   $product_initials[($i - 65)] = chr($i); 
}
Mark
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You can also do:

Code: Select all

for ($i = 'a', $j = 1; $j <= 26; $i++, $j++) {
    $letters[$j] = $i;
}
Mac
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

You can also do:

Code: Select all

$letters = range('a', 'z');
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post by Dale »

Jason's seems more simpler :)
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

Yeah it is. range() can also create an array for you from a given 'start' number till an 'end' number. Probably want to look it up in the functions reference.

It saves me a lot of time wondering it there's 27 or 25 letters in the alphabet.

doh!

-Nay
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post by Dale »

27 or 25 :haha: ;)
Post Reply