<? PHP function Build_order_no () { returndate(' Ymd '). Substr(implode(NULLarray_mapstr_split(substr( Uniqid(), 7, 1)), 0, 8); } echo build_order_no ();
Output results
2014062356100485
2014062349535399
The
uses uniqid to get a unique, non-repeating string that is generated based on the current microsecond number (but his first 7 bits seem to change for a long time, so do not consider the deletion) and take its 8th to 13th place. But this string contains the English alphabet, what should I do? The
uses Ord to get his ASCII code, so there's the next step: Use Str_split to split the string into arrays and use Array_map to manipulate it (faster). The
then returns an array, KO, using implode to make a string, 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 afraid of the tune, Brother does not believe he will be in the same microsecond two orders, network data transmission also points to time, even if you are local.