我正在处理我在Laravel的毕业设计,并希望生成小的唯一ID“9char max”...我不需要UUID,因为这将生成36个字符,这太长了。
发布于 2019-09-29 14:16:46
您可以像这样使用PHP函数:
function unique_code($limit)
{
return substr(base_convert(sha1(uniqid(mt_rand())), 16, 36), 0, $limit);
}
echo unique_code(9);输出如下所示:
s5s108dfc以下是规格说明:
或者在Laravel中,您可以使用laravel Str库:只需使用以下内容:
use Illuminate\Support\Str;
$uniqid = Str::random(9);发布于 2019-09-29 14:17:06
你可以用这个库生成一个随机字符串:
使用Illuminate\Support\Str;
$id =字符串::随机(9);
发布于 2019-09-29 14:25:52
你可以用这个,
$unique_id= echo floor(time()-999999999);这将根据时间生成一个9位数的唯一值。
https://stackoverflow.com/questions/58152743
复制相似问题