Home > Backend Development > PHP Tutorial > PHP生成唯一订单号方案。

PHP生成唯一订单号方案。

WBOY
Release: 2016-06-23 13:36:45
Original
1215 people have browsed it

第一种

return date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
Copy after login

第二种

return date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
Copy after login

第三种

//生成24位唯一订单号码,格式:YYYY-MMDD-HHII-SS-NNNN,NNNN-CC,其中:YYYY=年份,MM=月份,DD=日期,HH=24格式小时,II=分,SS=秒,NNNNNNNN=随机数,CC=检查码  @date_default_timezone_set("PRC");  while(true){   //订购日期   $order_date = date('Y-m-d');   //订单号码主体(YYYYMMDDHHIISSNNNNNNNN)   $order_id_main = date('YmdHis') . rand(10000000,99999999);   //订单号码主体长度   $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));   }   //唯一订单号码(YYYYMMDDHHIISSNNNNNNNNCC)   $order_id = $order_id_main . str_pad((100 - $order_id_sum % 100) % 100,2,'0',STR_PAD_LEFT);
Copy after login
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