Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get all alpabetic letters in PHP?

Tags:

php

How can I get all alphabetic letters?

I need to get all alphabetic letters in an array like: array('a','b','c'...);

like image 446
Ben Avatar asked Feb 02 '11 17:02

Ben


3 Answers

Use range function like this:

$letters = range('a', 'z');
print_r($letters);

Result:

Array
(
    [0] => a
    [1] => b
    [2] => c
    [3] => d
    [4] => e
    [5] => f
    [6] => g
    [7] => h
    [8] => i
    [9] => j
    [10] => k
    [11] => l
    [12] => m
    [13] => n
    [14] => o
    [15] => p
    [16] => q
    [17] => r
    [18] => s
    [19] => t
    [20] => u
    [21] => v
    [22] => w
    [23] => x
    [24] => y
    [25] => z
)
like image 112
Sarfraz Avatar answered Oct 19 '22 23:10

Sarfraz


Use range to do this, which makes it easy.

$az = range('a', 'z');
like image 38
Darren Avatar answered Oct 19 '22 23:10

Darren


for($i=65; $i<=90; ++$i) print chr($i)

65 is the ascii code for A

like image 34
Foo Bah Avatar answered Oct 20 '22 01:10

Foo Bah