PHP生成唯一订单号

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,或者时分秒。

猜你喜欢

转载自www.cnblogs.com/jiqing9006/p/9082322.html