I have a function GetLetters that returns
-
awhen I give it1 -
bwhen I give it2 -
zwhen I give it26 -
aawhen I give it27 -
abwhen I give it28
Basically you’d get the idea, this is my solution however it is looping indefinitely when I supply any input value above 26, does anyone know what’s wrong with it ?
function GetLetter($amt){
if($amt<=26){
return strtolower(chr(64+$amt));
}
$letters=array();
while(true){
$quotient=$amt%26;
array_unshift($letters,GetLetter($quotient===0?26:$quotient));
$amt=floor(($amt-1)/26);
if($amt===0){
break;
}
}
return implode("",$letters);
}
See here, you’re comparing floats. Try
intval().So change
to