Home > Backend Development > PHP Tutorial > PHP generates a unique order number, PHP generates an order number_PHP tutorial

PHP generates a unique order number, PHP generates an order number_PHP tutorial

WBOY
Release: 2016-07-13 09:47:14
Original
811 people have browsed it

PHP generates a unique order number, PHP generates an order number

I searched online and found that this classmate’s idea is quite good, redtamo, please go and check it out for details. Look, let me give a brief overview. This method uses English letters, year, month, day, Unix timestamp, microseconds, and random numbers. The possibility of duplication is greatly reduced, which is still very good. The use of letters is very representative, one letter corresponds to one year, a total of 16 digits, no more, no less.

1.

Copy code The code is as follows: $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(' d', rand(0, 99));
?>

Generation effect:

A422694333616096
Copy after login

2.

Copy code The code is as follows: 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
Copy after login

The above is the entire content of this article, I hope you all like it.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1027048.htmlTechArticlePHP generates a unique order number. PHP generates an order number. After searching online, I found that this classmate had a very good idea. Not bad, redtamo, please go and check it out for details, I will give a brief overview, the method...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template