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

Source: Internet
Author: User

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

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.

1.

Copy 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 ));
?>

Effect:

A422694333616096

2.

Copy codeThe 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.