This article mainly introduces the idea and example of a netizen using PHP to generate a unique order number. it feels very good. if you need a friend, you can refer to it and find it online, I found this student had a good idea, redtamo. please take a look at the specifics. 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.
The 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.
The 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.