php - 从当前日期时间生成唯一的交易 ID

我需要在 PHP 中使用日期时间生成唯一的交易 ID。它应该是大约 17-20 个字符的数字格式。 (喜欢 2017041914495412346)
谁能帮帮忙?
提前致谢..

最佳答案

像这样的东西对你有用:

    <?php
function getGUIDnoHash(){
            mt_srand((double)microtime()*10000);
            $charid = md5(uniqid(rand(), true));
            $c = unpack("C*",$charid);
            $c = implode("",$c);

            return substr($c,0,20);
    }


echo getGUIDnoHash();
?>

既然你说的是字符,这将只包括数字。并且将是 20 个字符。当然,因为它只是数字并且限制在 20 个字符以内,所以这不是永远唯一的,因此您需要在代码中添加一个检查。

https://stackoverflow.com/questions/43653275/

相关文章:

php - 当要比较的元数据是序列化数组时,Wordpress meta_query 值数组?

angular - HTML5 Websql - 如何与 Ionic 3 和 Angular 4 一

arrays - Swagger 的对象数组

c# - Unity Particle Collider 与粒子

sql - 在 SQL Server 中将所有表数据类型从文本更改为 varchar

php - Laravel Eloquent : route model binding not w

vim - 将行合并到 vim 中的段落

linux - 错误 "caution: filename not matched"- 解压缩命令

r - 在 shinyapps.io 中部署 R 应用程序 - "Error:parsing man

perl - 在 Perl 中打印哈希值