Way to get all alphabetic chars in an array in PHP?

ID : 20050

viewed : 14

Tags : phpphp

Top 5 Answer for Way to get all alphabetic chars in an array in PHP?

vote vote

91

$alphas = range('A', 'Z'); 

Documentation: https://www.php.net/manual/en/function.range.php

vote vote

89

To get both upper and lower case merge the two ranges:

$alphas = array_merge(range('A', 'Z'), range('a', 'z')); 
vote vote

78

$alphabet = 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'); 
vote vote

62

Another way:

$c = 'A'; $chars = array($c); while ($c < 'Z') $chars[] = ++$c; 
vote vote

54

PHP has already provided a function for such applications.
chr(x) returns the ascii character with integer index of x.
In some cases, this approach should prove most intuitive.
Refer http://www.asciitable.com/

$UPPERCASE_LETTERS = range(chr(65),chr(90)); $LOWERCASE_LETTERS = range(chr(97),chr(122)); $NUMBERS_ZERO_THROUGH_NINE = range(chr(48),chr(57));  $ALPHA_NUMERIC_CHARS = array_merge($UPPERCASE_LETTERS, $LOWERCASE_LETTERS, $NUMBERS_ZERO_THROUGH_NINE);  

Top 3 video Explaining Way to get all alphabetic chars in an array in PHP?

Related QUESTION?