<?php
$colLetter = '';
$colLetter = function($num) use(&$colLetter) {
$letters=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');
//if the number is greater than 26, calculate to get the next letters
if($num > 26) {
//divide the number by 26 and get rid of the decimal
$comp = floor($num / 26);
//add the letter to the end of the result and return it
if ($comp != 0) {
// don't subtract 1 if the comparative variable is greater than 0
return $colLetter($comp) . $letters[($num - $comp * 26)];
} else {
return $colLetter($comp) . $letters[($num - $comp * 26) - 1];
}
}
return $letters[($num-1)];
};