문제

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.

Hope I am clear with my ques. How to do that?

도움이 되었습니까?

해결책

Using time() to create sortable unique id's

Concatenating strings will also further randomize your desired result and still keep it sortable. manual here

$uniqueId= time().'-'.mt_rand();

다른 팁

You can use a combination of uniqid() and time() like so:

$s = uniqid(time(), true);

Example output:

1346136883503c6b3330caf5.19553126

Is this what you're looking for? uniqid()

From the doc:

Gets a prefixed unique identifier based on the current time in microseconds.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top