How to list from A to Z in PHP, and then on to AA, AB, AC, etc

PHP has the string increment operator that does exactly that:

for($x = 'A'; $x < 'ZZ'; $x++)
    echo $x, ' ';

Result:

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 AA AB AC AD AE AF... 

Ref:

PHP follows Perl's convention when dealing with arithmetic operations on character variables and not C's. For example, in PHP and Perl $a = 'Z'; $a++; turns $a into 'AA', while in C a = 'Z'; a++; turns a into '[' (ASCII value of 'Z' is 90, ASCII value of '[' is 91). Note that character variables can be incremented but not decremented and even so only plain ASCII alphabets and digits (a-z, A-Z and 0-9) are supported. Incrementing/decrementing other character variables has no effect, the original string is unchanged.

http://php.net/manual/en/language.operators.increment.php

Tags:

Php