Skip to content

Instantly share code, notes, and snippets.

@justindmartin
Created September 4, 2013 03:38
Show Gist options
  • Save justindmartin/6432525 to your computer and use it in GitHub Desktop.
Save justindmartin/6432525 to your computer and use it in GitHub Desktop.
This converts answer choice numbers to letters.
function convertAnswerNumberToLetters($number){
$LETTERS_DICTIONARY = 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');
$MAX_ITERATIONS = 20;
$letters = '';
$numIterations = 0;
while($number > 0 && $numIterations <= $MAX_ITERATIONS){
$index = $number;
for($temp = 0; $temp < $MAX_ITERATIONS && $temp < $number && $temp > 26; $temp -= 26){
$index = $temp;
}
$letters .= $LETTERS_DICTIONARY[$index-1];
$number -= 26;
$numIterations++;
}
return strtoupper($letters);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment