Answer the question
In order to leave comments, you need to log in
Why does the time() function run in a loop return the same value?
Elementary code:
for ($i = 0; $i < 20; $i++){
echo time() . '<br>';
}
foreach ($files as $file) {
$name = time();
$file->move(public_path('upload/' . $path_name . '/' . $id), $name . '.' . $file->getClientOriginalExtension());
}
Answer the question
In order to leave comments, you need to log in
1.microtime(true);
2. do not do this. Suddenly 2 files will load at the same time. Name the hash of the file
Enjoy:
for ($i = 0; $i < 20; $i++){
echo time() . '<br>';
sleep(1);
}
It's hard to guess that the loop takes milliseconds?
Write microtime(true) - check out the difference.
Returns the number of seconds that have elapsed since the beginning of the Unix Epoch (The Unix Epoch, January 1, 1970 00:00:00 GMT) until the current time.
Apparently this number has not changed.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question