PHP generates a unique order number, and PHP generates an order number
After searching for a redtamo on the internet, I found this student had a good idea. Please take a look at the details. I will give a brief overview, this method uses English letters, year, month, and day, Unix timestamps, microseconds, and random numbers. The possibility of repetition is greatly reduced, which is quite good. The use of letters is very representative. A letter corresponds to a year, a total of 16 characters, not many.
1.
Copy codeThe Code is as follows: <? Php
$ YCode = array ('A', 'B', 'C', 'D', 'E', 'F', 'G', 'h ', 'I', 'J ');
$ OrderSn = $ yCode [intval (date ('y')-2011]. strtoupper (dechex (date ('M '))). date ('D '). substr (time (),-5 ). substr (microtime ()] 2, 5 ). sprintf ('% 02d', rand (0, 99 ));
?>
Effect:
A422694333616096
2.
Copy codeThe Code is as follows: <? Php
Function build_order_no (){
Return date ('ymmd '). substr (implode (NULL, array_map ('ord ', str_split (substr (uniqid (), 7, 13), 1), 0, 8 );
}
Echo build_order_no ();
?>
Output result:
20140623561004852014062349535399
The above is all the content of this article. I hope you will like it.