Incrementing Alphanumeric strings in PHP

I ran into a problem the other day where I needed to increment an alphanumeric string. An alphanumeric string is a string consisting of both numerals and letters (0-9, a-z, A-Z). This combination of characters is base62, however, there is no base62 function in PHP to make this easy. There were a couple of solutions out there, but I didn’t really like any of them. So I decided to sit down and write out one that suited my needs. Here it is:

I also created a GitHubGist for this snippet.