Remember: Before the interview was the interviewer asked the resume item in the order number I was what the rules generated, I blew my head, nonsense a pass, rely on! Today in the company's project order number generation, curiosity, looked under, is the online this just.
1*2*uniqid-This is what the authorities say:3* Gets A prefixed unique identifier based on the Current TimeIn microseconds.4*/5 functionbuild_order_no ()6 {7 return Date(' YMD ').substr(implode(NULL,Array_map(' Ord ',Str_split(substr(uniqid(), 7, 13), 1)), 0, 8);8 9 //I'm going to add one more random number to the back.Ten return Date(' YMD ').substr(implode(NULL,Array_map(' Ord ',Str_split(substr(uniqid(), 7, 13), 1)), 0, 8).Strval(Rand(100,999)); One A}
Uniqid gets a unique, non-repeating string based on the current number of microseconds (but his first 7 bits seem to change for a long time, so don't worry about deleting it), take 8th to 13th. But this string contains the English alphabet, what should I do?
Use Ord to get his ASCII code, so there's the next step: use Str_split to divide the string into arrays and use Array_map to manipulate it (faster).
Then returned is an array, KO, in a string with implode, but the character length is variable, take the previous fixed several, and then precede the current year and date, this method generates the order number, the world will not have much repetition.
Of course, unless you put the server time forward, but not to worry about the tune, brother do not believe he will be in the same microsecond two orders, network data transmission also points to the time, even if you are local.
----Text Parsing section for reprint!
PHP generates a unique order number