Random ID/Number Generator in PHP

前端 未结 4 1478
伪装坚强ぢ
伪装坚强ぢ 2021-01-17 05:29

I am building a list of \"agent id\'s\" in my database with the following requirements:

  1. The ID must be 9 digits long (numeric only)
  2. The ID may not con
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-17 06:14

    For second condition, you can create an array like this

    $a = array( 0,0,1,1,2,2,3,3.....,9,9 );
    

    and get random elements: array_rand() (see manual) to get digit, append it to your ID and remove value from source array by unsetting at index.

    Generally, this solving also third condition, but this solution excludes all ID's with possible and acceptable three digits

提交回复
热议问题