php 如何根据当前数据和时间在php中生成唯一ID?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12153902/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to generate unique id in php based on current data and time?
提问by user1518659
I need to generate a unique ID in php based on current date and time to keep a log of when i am running code. i.e. every time i run the code it should be able to generate a unique id based on current date and time.
我需要根据当前日期和时间在 php 中生成一个唯一 ID,以记录我何时运行代码。即每次我运行代码时,它应该能够根据当前日期和时间生成一个唯一的 id。
Hope I am clear with my ques. How to do that?
希望我清楚我的问题。怎么做?
回答by amitchhajer
回答by Ja?ck
You can use a combination of uniqid()and time()like so:
您可以使用组合uniqid()和time()像这样:
$s = uniqid(time(), true);
Example output:
示例输出:
1346136883503c6b3330caf5.19553126

