Unique, unpredictable, 12 digit, integer id

前端 未结 7 1093
被撕碎了的回忆
被撕碎了的回忆 2021-01-13 06:56

How would I go about generating this... I want to keep my primary key sequential and have a 12 digit unique pin generated for each new object added to the database.

相关标签:
7条回答
  • 2021-01-13 07:29
    <?php 
    $allowed_characters = array(1,2,3,4,5,6,7,8,9,0);
    for($i = 1;$i <= 12; $i++){
        $pass .= $allowed_characters[rand(0, count($allowed_characters) - 1)];
    }
    echo $pass;
    ?>
    

    demo: http://sandbox.phpcode.eu/g/c0190/4

    0 讨论(0)
提交回复
热议问题