Home > php教程 > php手册 > PHP生成唯一订单号,PHP生成订单号

PHP生成唯一订单号,PHP生成订单号

WBOY
Release: 2016-06-13 08:58:41
Original
1256 people have browsed it

PHP生成唯一订单号,PHP生成订单号

在网上找了一番,发现这位同学的想法挺不错的,redtamo,具体的请稳步过去看看,我作简要概述,该方法用上了英文字母、年月日、Unix 时间戳和微秒数、随机数,重复的可能性大大降低,还是很不错的。使用字母很有代表性,一个字母对应一个年份,总共16位,不多也不少.

1.

复制代码 代码如下:      $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));
?>

生成效果:

A422694333616096
Copy after login

2.

复制代码 代码如下:<?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();
?>

输出结果:

2014062356100485
2014062349535399
Copy after login

以上所述就是本文的全部内容了,希望大家能够喜欢。

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template