Created
September 4, 2013 03:38
-
-
Save justindmartin/6432525 to your computer and use it in GitHub Desktop.
This converts answer choice numbers to letters.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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