18 not repeat order number

18 not repeat order number

/ * * 
* 10 never repeat generated order number 
* / 
function ORDER_NUMBER () {
     static  $ ORDERSN = Array ();                                         // static variable 
    $ ORS = DATE . ( 'YMD') substr ( Time (), -. 5) . substr ( microtime, and (), 2,5);      // generates a 16-digit number substantially 
    iF ( isset ( $ ORDERSN [ $ ORS ])) {                                     // determines whether the basic order number 
        $ ORDERSN [ $ ORS] ++;                                            // if present, the value of the increment. 1 
    } the else {
         $ ORDERSN [ $ ORS ] =. 1 ; 
    } 
    return  $ ORS . Str_pad ( $ ORDERSN [ $ ORS ], 2, '0', STR_PAD_LEFT);      / / link string 
}

Being only a local test, if needs more complicated, consider static variables into a static cache judge

Plus the user id is certainly not duplicate

function create_sn(){
    mt_srand((double )microtime() * 1000000 );
    return date("YmdHis" ).str_pad( mt_rand( 1, 99999 ), 5, "0", STR_PAD_LEFT );
}

 

Guess you like

Origin www.cnblogs.com/bluealine/p/11040833.html