Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cleaner alphabet array in php

Tags:

arrays

php

I'm creating an array of alphabet letters.. It's cluttering the code and doesn't look too good for readability. Does PHP have a cleaner way or a function that already returns the alphabet in an array?

array ('a','b','c','d','e','f','g'..........................................);
like image 225
sami Avatar asked Dec 01 '10 04:12

sami


2 Answers

You can use the range function which is used to create an array containing range of elements:

$alpha = range('a', 'z');

See it

like image 102
codaddict Avatar answered Oct 16 '22 08:10

codaddict


Just so no one has to attempt it, you can also do the same with capital letters:

$alpha = range('A', 'Z');
like image 35
Darryl Hein Avatar answered Oct 16 '22 07:10

Darryl Hein