PHP generates a summary of unique order numbers, and php order numbers. PHP generates a summary of the unique order number method, php order number summary the first copy code is as follows: returndate (Ymd ). str_pad (mt_rand (1,99999), 5, 0, STR_PAD_LEFT); method for generating unique order numbers in PHP; and method for collecting php order numbers
First
The code is as follows:
Return date ('ymmd'). str_pad (mt_rand (1, 99999), 5, '0', STR_PAD_LEFT );
Second
The code is as follows:
Return date ('ymmd '). substr (implode (NULL, array_map ('ord ', str_split (substr (uniqid (), 7, 13), 1), 0, 8 );
Third
// Generate 24-bit unique order number, format: YYYY-MMDD-HHII-SS-NNNN, NNNN-CC, where: YYYY = year, MM = month, DD = date, HH = 24 format hour, II = minute, SS = second, nnnnnnnnnn = random number, CC = check code @ date_default_timezone_set ("PRC"); while (true) {// order date $ order_date = date ('Y-m-D'); // order number subject (yyyymmddhhi1_nnnnnnn) $ order_id_main = date ('ymdhis '). rand (, 99999999); // length of the subject of the order number $ order_id_len = strlen ($ order_id_main); $ order_id_sum = 0; for ($ I = 0; $ I <$ order_id_len; $ I ++) {$ order_id_sum + = (int) (substr ($ order_id_main, $ I, 1);} // unique order number (yyyymmddhhi1_nnnnnnncc) $ order_id = $ order_id_main. str_pad (100-$ order_id_sum % 100) %, 2, '0', STR_PAD_LEFT );
Fourth:
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 also a lot, haha.
<?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:
The code is as follows: A422694333616096
Alas, but unfortunately, this method is not used in the final project. it is said that it is not necessary to make such a complicated project ,--!
The above four methods are all shared in this article. I hope you will like them.
The first type of signature code is as follows: return date ('ymmd'). str_pad (mt_rand (1, 99999), 5, '0', STR_PAD_LEFT); the second type of complexity...