I’d like to be able to output a letter in the same way that upper-alpha ordered lists do in HTML. For example:
<?php
$letter_counter = 1;
echo get_letter($letter_counter);
// Output should be "A".
$letter_counter = 2;
echo get_letter($letter_counter);
// Output should be "B".
$letter_counter = 26;
echo get_letter($letter_counter);
// Output should be "Z".
$letter_counter = 27;
echo get_letter($letter_counter);
// Output should be "AA".
$letter_counter = 28;
echo get_letter($letter_counter);
// Output should be "AB".
$letter_counter = 52;
echo get_letter($letter_counter);
// Output should be "AZ".
?>
It should be able to go on indefinitely. What would the code for the “get_letter” function look like? I think the code shown on this page could be helpful, but I’m not sure how to get it to do what I want to do.
Thanks!
Why bother with $letter_counter = 2; (as a number) and just simply specify the last letter that you want.
Something like this might be of interest though:
(You were aware that you can increment strings as well as number, weren’t you?)