Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

How to generate alphanumeric ID

How to generate alphanumeric ID that starter with alphabet the follow by numbers. But i don't want generate randomly. How can i generate alphanumeric ID in increment order?

1 Answer

You can split it into a string and a number, and then concat them into one string. Then you can use a loop to increment the number and generate the next ID. Pseudo-code example (java style):

String generatedID;

String letters = "ABC" //or any other letter you want
int number = 123 //or any number you want to start with


for (int i=0; i++; i<10) {
    generatedID = letters + convertToString(number);
    number++;
}
// will generate:
// ABC123... ABC124... ABC125... and so on.