I would like to write a function that takes in 3 characters and increments it and returns the newly incremented characters as a string.
I know how to increase a single letter to the next one but how would I know when to increase the second letters and then stop and then increase the first letter again to have a sequential increase?
So if AAA is passed, return AAB. If AAZ is passed return ABA (hard part).
I would appreciate help with the logic and what php functions will be useful to use.
Even better, has some done this already or there is a class available to do this??
Thanks all for any help
I have these methods in c# that you could probably convert to php and modify to suit your needs, I'm not sure Hexavigesimal is the exact name for these though...
EDIT
I see by the other answers that in PHP you can use
++
instead, nice!You are looking at a number representation problem. This is base24 (or however many numbers your alphabet has). Lets call the base b.
Assign a number to each letter in alphabet (A=1, B=2, C=3).
Next, figure out your input "number": The representation "ABC" means
A*b^2 + B*b^1 + C*b^0
Use this formula to find the number (int). Increment it.Next, convert it back to your number system: Divide by
b^2
to get third digit, the remainder (modulo) byb^1
for second digit, the remainder (modulo) by `b^0^ for last digit.This might help: How to convert from base10 to any other base.