All alphabetic characters in an array can be achieved by using chr(), range() with for and foreach loop in PHP. To display the array elements as output we can use echo, print_r() and var_dump() function.
Using range() function: This function is used to create an array of elements of any kind such as integer, alphabets within a given range (from low to high) i.e, the first element of list is considered as low and last one is considered as high. It returns an array of alphabets if the range from A to Z i.e. range(A, Z).
array range( mixed first, mixed second, number steps )
Example 1: Below example illustrate how to display an array of all alphabetic character using range() function.
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,
Example 2: Below example illustrate how to display an array of all Alphabetic character using range() function along with array_combine.
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 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
Using chr() function: The chr() function is used to convert an ASCII value to a character. It accepts an ASCII value as a parameter and returns a string representing a character from the specified ASCII value. The ASCII value can be specified in decimal, octal, or hex values. It returns an array of alphabet if the chr() has its ASCII values from 65 to 91 for alphabet.
string chr( <>int $value )
Example 1: Below example illustrate to display an array of all Alphabetic character using ASCII values.
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,
Example 2: Below example illustrate to display an array of all Alphabetic character using ASCII values with the help of chr() function.
65 => A, 66 => B, 67 => C, 68 => D, 69 => E, 70 => F, 71 => G, 72 => H, 73 => I, 74 => J, 75 => K, 76 => L, 77 => M, 78 => N, 79 => O, 80 => P, 81 => Q, 82 => R, 83 => S, 84 => T, 85 => U, 86 => V, 87 => W, 88 => X, 89 => Y, 90 => Z,
- PHP | ctype_alpha() (Checks for alphabetic value)
- PHP | Get PHP configuration information using phpinfo()
- How to get names of all the subfolders and files present in a directory using PHP?
- How to get the first element of an array in PHP?
- How to get random value out of an array in PHP?
- How to get numeric index of associative array in PHP?
- How to loop through an associative array and get the key in PHP?
- PHP | dir() (Get instance of the Directory)
- HTTP GET and POST Methods in PHP
- How to get file name from a path in PHP?
- PHP | Ds\Deque get() Function
- Get the full URL in PHP
- How to get multiple selected values of select box in php?
- How to get the last n characters of a PHP string?
- How to get current function name in PHP?
- How to get name of calling function/method in PHP ?
- PHP | Ds\Sequence get() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.