I looked online and found that this classmate had a good idea, redtamo. Please go and take a look at the specific details. I gave a brief overview. This method uses English letters, year, month, day, Unix timestamps, microseconds, and random numbers. The possibility of repetition is greatly reduced, which is still very good. Using letters is very representative. One letter corresponds to a year, with a total of 16 digits, no more or less.
1.
Copy the 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));
?>
$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));
?>
Generate effect:
A422694333616096
2.
Copy the codeThe code is as follows:
<?php
function build_order_no(){
return date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
}
echo build_order_no();
?>
function build_order_no(){
return date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
}
echo build_order_no();
?>
Output result:
2014062356100485 2014062349535399
The above is the entire content of this article, I hope you like it.