开发者

How can I get all alpabetic letters in PHP?

开发者 https://www.devze.com 2023-02-08 08:09 出处:网络
How can I get all alphabetic letters? I need to get all alphabetic letters in an array like: array(\'a\',开发者_如何学C\'b\',\'c\'...);Use range function like this:

How can I get all alphabetic letters?

I need to get all alphabetic letters in an array like: array('a',开发者_如何学C'b','c'...);


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
)


Use range to do this, which makes it easy.

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


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

65 is the ascii code for A


$lower = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');

$upper = array('A', 'B', 'C', 'D', 'E', 'F', 'G','H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');

For problems that have finite solutions, sometimes the best thing you can do is just hard code each one.


$alphas = range('A', 'Z');
foreach($alphas as $value){
    echo $value."<br>";
}

Print A-Z Result

try this....

Output is:

A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z


You can also do this with my example.

<?php

$letters =  '=======Alphabets========' . PHP_EOL;
echo  $letters;

$alphabets = "A";

for ($i=0; $i < strlen($letters); $i++) { 
   echo "<br>".$alphabets++ . PHP_EOL;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消