简体   繁体   中英

PHP microtime()

Here is my code:

<?
    $time = microtime();
    $len = strlen($time);
    echo $time;
    echo"<br>".$len."<br>";
    $micro;
    $i = 0;
    while ($time{$i} != " ")
    {
        $micro{i}=$time{i};
        echo $micro{i};
        $i=$i+1;
    }
?>

The output I'm getting is 0000000000 (that is $micro). Here I'm trying to get the microseconds part of the output.

Is there anything wrong?

Use microtime(true) instead.

$time = microtime(true);
$micro = $time - floor($time); // microseconds part

Use $micro{$i}=$time{$i}; instead of $micro{i}=$time{i};

But much better way to do stuff like this:

list($timestamp, $microseconds) = split(" ", microtime());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM