Home  >  Article  >  Backend Development  >  PHP generates a unique order function to share, PHP order function_PHP tutorial

PHP generates a unique order function to share, PHP order function_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:08:20833browse

php generates a unique order function to share, php order function

Solution about generating order number

There are more and more e-commerce and e-commerce-like systems. I believe that the order number problem is the most common problem in such systems, but I still want to talk about it today.

Due to work needs, I took over a trading system developed by another colleague in the past few days. It was originally generated using the uniqid() function. Theoretically, there will be no duplication, but due to some special reasons, we have to create a new order number generation function

Copy code The code is as follows:

/**
* Generate a unique order number 20110809111259232312
* 2011-Date
* 08-Month
* 09-Date
* 11-hours
* 12-minutes
* 59-seconds
* 2323-microseconds
* 12-random value
* @return string
​​*/
Public function trade_no() {
list($usec, $sec) = explode(" ", microtime());
          $usec = substr(str_replace('0.', '', $usec), 0,4);
$str = rand(10,99);
         return date("YmdHis").$usec.$str;
}

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/951634.htmlTechArticlePHP generates unique order function sharing, php order function is a solution for generating order numbers for e-commerce and similar e-commerce There are more and more systems. I believe the order number problem is caused by this type of system...
Statement:
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