Support changing length
/**
* Generate unique order number
*
*/function build_order_no(){<br>
Return date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);<br>
}
Note:
Use uniqid to obtain a unique and unique string generated based on the current number of microseconds (but the first 7 digits seem to change for a long time, so you can delete it without considering it), and take the 8th to 13th digits. But there are English letters in this string, what should I do?
Use ord to get his ASCII code, so there is the next step: use str_split to split the string into an array, and use array_map to operate (faster).
Then what is returned is still an array, KO, which is converted into a string using implode, but the character length is variable. Take the first fixed few digits, and then add the current year and date in front. The order number generated by this method will not be used in the world. How many duplicates are there.
Of course, unless you adjust the server time forward, don't be afraid to adjust it. I don't believe that he will place two orders in the same microsecond. Network data transmission also takes time, even if you are local.