marie1995
marie1995

Reputation: 59

Time() Function in PHP always shows same value

If I use time() in a loop, I always get the same values for time. But time should be a function and not a variable, so I dont understand what the problem is.

<?php

$i= 0;

while($i < 1000)
{
?>
 <br>
<?php
echo time();
$i= $i +1;
}

?>

Upvotes: 2

Views: 776

Answers (1)

ggorlen
ggorlen

Reputation: 56895

According to the docs for time(), it

Returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).

Emphasis mine. while ($i < 1000) will likely execute in under a second, so all of the timestamps are quite likely to be the same for any given run of the program (but should be different on the next run).

Upvotes: 3

Related Questions