I’m working on something which requires unique ID numbers which are in the format of:
[A-Z][A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9]
And increment as:
AAAAAA, AAAAAB, … AAAAAZ, AAAAA0, AAAAA1, .. AAAAA9, AAAABA, AAAABB
I know I can increment letters in PHP, but how would I do letters and numbers in such a way?
Special note, baseconvert isn’t an option, because it must always be exactly 6 characters and fit the noted format incrementally. Further, baseconvert starts at 0, not A, so if I do start at “621937810” (AAAAAA) the next jump will be after AAAAAZ and on to AAAAB0. It seemed like the quickest solution, but it doesn’t work.
you could try base_convert from 36 to 10, increment then 10 to 36. I didn’t have any trouble with the larger numbers like
ZZZZZW+1, however as it says in the php manual, there could be problems with larger numbers due to float/double precision.outputs:
example can be see here
Other than that, you can do some custom increment or even check out the base_convert comments in the php manual on converting some larger bases and values.
Edit after clarification:
Taken from the php comments page:
working example
As for incrementing from the string ID, I would suggest either saving the integer value, increment that and convert or write a similar function to convert to integer, increment, convert back. The former probably being easier.
And as far as forcing the same 6 character format, the only time this should be a problem is when you pass the Z99999 which according to your format, is the max.