PHP生成唯一订单号
在网上找了一番,发现这位同学的想法挺不错的,redtamo,具体的请稳步过去看看,我作简要概述,该方法用上了英文字母、年月日、Unix时间戳和微秒数、随机数,重复的可能性大大降低,还是很不错的。使用字母很有代表性,一个字母对应一个年份,总共16位,不多也不少.
1.
<?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)); ?>
生成效果:
A422694333616096
2.
<?php functionbuild_order_no(){ returndate('Ymd').substr(implode(NULL,array_map('ord',str_split(substr(uniqid(),7,13),1))),0,8); } echobuild_order_no(); ?>
输出结果:
2014062356100485 2014062349535399
以上所述就是本文的全部内容了,希望大家能够喜欢。