3
I am creating a function that returns the alphabet to me in an array according to the size of columns passed.
At first I was only making a loop using the range("A", "Z"); but when I had more than 26 columns no longer attended me, with this, searching the internet, what I found was a suggestion here http://forum.imasters.com.br/topic/532733-repetir-o-alfabeto-varias-vezes-como-as-colunas-do-excel/ given by the reply of Willian Bruno, but that is also not very correct, at least it did not work here, dai using as a base I created mine only that also does not return me the expected, that would be the alphabet (a-z, aa-zz, aaa-zzz), similar to the columns of excel.
follow what I’m doing.
function alphaRepeat($columnsSize = 10)
{
$i = 0;
$j = 0;
$abc = range("A", "Z");
$abcSize = count($abc);
$alpha = array();
while ($i < $columnsSize) {
if (((int)($i / $abcSize) - $j) > 0) {
$j++;
}
$item = '';
if ($j > 0) {
$item.= str_repeat($abc[$j - 1], $j);
}
$item.= $abc[$i - ($abcSize * $j)];
$alpha[] = $item;
$i++;
}
return $alpha;
}
If the
$columnSize
for 5 it must go froma
untile
? if it is 27 ofa
up toaa
?– rray
If it’s 1 to 52 then it has to be
a
untilaz
. if it is 1 to 53 then it has to bea
until 53ba
and so on– Marcelo Diniz