具有逻辑顺序的字母的数字

I have this array which links numbers to letters at the moment like this:

1-26 = A-Z

But there is more, 27=AA and 28=AB etc...

so basically when I do this:

var_dump($array[2]); //shows B
var_dump($array[29]); //shows AC

Now this array I made myself but it's becoming way too long. Is there a way to actually get this going on till lets say 32? I know there is chr but I dont think I can use this.

Is there an easier way to actually get this without using this way too long of an array?

It's slower calculating it this way, but you can take advantage of the fact that PHP lets you increment letters in the same way as numbers, Perl style:

function excelColumnRange($number) {
    $character = 'A';
    while ($number > 1) {
        ++$character;
        --$number;
    }
    return $character;
}

var_dump(excelColumnRange(2));
var_dump(excelColumnRange(29));

here is the code which you are looking for :

<?php 
    $start = "A";
    $max = 50;

    $result = array();
    for($i=1; $i<=$max; $i++) {
        $result[$i] = $start++;
    }

    print_r($result);
?>

Ref: http://www.xpertdeveloper.com/2011/01/php-strings-unusual-behaviour/

This should work for you:

Even without any loops. First I calculate how many times the alphabet (26) goes into the number. With this I define how many times it has to str_repleat() A. Then I simply subtract this number and calculate the number in the alphabet with the number which is left.

<?php

    function numberToLetter($number) {
        $fullSets = (($num = floor(($number-1) / 26)) < 0 ? 0 : $num);
        return str_repeat("A", $fullSets) . (($v = ($number-$fullSets*26)) > 0 ? chr($v+64) : ""); 
    }

     echo numberToLetter(53);

?>

output:

AAA