首页 > Web开发 > 详细

PHP生成唯一订单号

时间:2018-05-24 13:07:34      阅读:201      评论:0      收藏:0      [点我收藏+]
function create_order_no() {
    $order_no = date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8).rand(1000,9999);
    return $order_no;
}
function create_order_no() {
    $order_no = date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT).rand(1000,9999);
    return $order_no;
}
function create_order_no() {
    $yCode = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
    $order_no = $yCode[intval(date('Y')) - 2017] . strtoupper(dechex(date('m'))) . date('d') . substr(time(), -5) . substr(microtime(), 2, 5) . sprintf('%02d', rand(1000, 9999));
    return $order_no;
}

如果担心重复,可以加个uid,或者时分秒。

PHP生成唯一订单号

原文:https://www.cnblogs.com/jiqing9006/p/9082322.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!