".$len."
"; $micro; $i = 0; while ($t...">

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 get is 0000000000 (i.e. $ micro). Here I am trying to get the microsecond part of the output.

Is there something wrong?

+3
source share
2 answers

Use microtime(true)instead.

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

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

But a much better way to do things like this:

($ timestamp, $ micececonds) = split ("", microtime ());

+1
source

Source: https://habr.com/ru/post/1769478/


All Articles