Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP microtime()

Tags:

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?

like image 951
Anant Avatar asked May 17 '26 04:05

Anant


1 Answers

Use microtime(true) instead.

$time = microtime(true);
$micro = $time - floor($time); // microseconds part
like image 89
zerkms Avatar answered May 19 '26 19:05

zerkms



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!