douxiaqin2062 2018-10-22 09:20
浏览 32
已采纳

在PHP中生成唯一字母表时出现问题

Am trying to generate a unique value in PHP where the first and last letters should be J and 1 respectively while the middle characters should be a series of aplhabetical letters and the whole value should be 7 in total eg JWERYH1 Please assist?

$let = chr(rand(65, 90));

$all = 'J' . $let . '1';

dd($all);
  • 写回答

3条回答 默认 最新

  • dongyi9330 2018-10-22 09:24
    关注

    Try this code

    $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    $res = "";
    for ($i = 0; $i < 5; $i++) {
        $res .= $chars[mt_rand(0, strlen($chars)-1)];
    }
    
    echo 'J'.$res.'1';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?