excel数组列double / triple / etc.辅音代

时间:2010-10-29 15:49:46

标签: php arrays excel

如何为AA-ZZ等自动生成数组(在PHP中),如AAA-ZZZ

$column_arr2= range("aa", "zz"); // NOT Working
$row_arr    = range(0,1000);
$column_arr = range("a", "z");

echo "Column2<pre>".print_r($column_arr2, true)."</pre><br />"; // prints a - z
echo "Row<pre>".print_r($row_arr, true)."</pre><br />";
echo "Column<pre>".print_r($column_arr, true)."</pre><br />";

我希望将数字和alpha数组设置为动态,因为我将它用于excel文档。

我想要的是:

$arr = ([0] => 'a', [1] => 'b', [2] => 'c', ...
        [26] => 'aa', [27] => 'ab', [28] => 'ac', ...
        [52] => 'ba', [53] => 'bb', [54] => 'bc', ...
       )

欢迎任何想法

1 个答案:

答案 0 :(得分:14)

PHP supports incrementing strings

$array = array('A');
$current = 'A';
while ($current != 'ZZZ') {
    $array[] = ++$current;
}