php microtime() format value

microtime, optimization, php

Solution

You can do the entire thing in one line using regex:

$value = preg_replace('/(0)\.(\d+) (\d+)/', '$3$1$2', microtime());

Example:

<?php
    $microtime = microtime();
    var_dump( $microtime );
    var_dump( preg_replace('/(0)\.(\d+) (\d+)/', '$3$1$2', $microtime) );
?>

Output:

string(21) "0.49323800 1385734417"  
string(19) "1385734417049323800"

DEMO

Problem

PHP's microtime() returns something like this: ``` 0.56876200 1385731177 //that's msec sec ``` That value I need it in this format: ``` 1385731177056876200 //this is sec msec without space and dot ``` Currently I'm doing something this: ``` $microtime = microtime(); $microtime_array = explode(" ", $microtime); $value = $microtime_array[1] . str_replace(".", "", $microtime_array[0]); ``` Is there a one line code to achieve this?

Original source