3

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Anant
  • 149
  • 3
  • 9

2 Answers2

7

Use microtime(true) instead.

$time = microtime(true);
$micro = $time - floor($time); // microseconds part
zerkms
  • 249,484
  • 69
  • 436
  • 539
1

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());

Kiryaka
  • 44
  • 3