Coding a general 4 digit alpha-numeric series

Trying to code a general 4 digit alphanumeric series in PHP.

Pattern is as follows

0000

0001

9999

A000

A001

A999

B000

Z999

AA00

AA99

AB00

ZZ99

AAA0

AAA9

AAB0

ZZZZ

I was trying to make the logic based on the no of Z and no of 9, but could not get anything concrete going.

I am trying to write a code that will return me the next number of the series on inputting the last number of the series.

Any hints or leads will be appreciated.

Thanks in advance.

I have a doubt regarding the pattern
After 9999 the next number is A000.
So following similar logic shouldn’t the next number after 0009 be 000A?

No, what we are doing is that we are exhausting all the number set first i.e 0000 - 9999
After we exhaust all the number set, After 9999 -> A000 Then exhaust all the number set with A i.e from A000 till A999->B000…till Z999 Now we have exhausted all the number range with single alphabet. So now next element will be AA00 and then the same pattern follows –