2019-06-03 11:27:55 0 Comments PHP Boy.Lee

Fix PHP Error A non well formed numeric value encountered

When we need calculate time in PHP we will used microtime function, but you may get error "A non well formed numeric value encountered",let's see why it happen

 

{ Error: A non well formed numeric value encountered }

$startTime = microtime(); //string(21) "0.43228200 1559370720"
$usedTime = microtime() - $startTime; //Error: A non well formed numeric value encountered

 

{ Correct Usage }

$startTime = microtime(true); //float(1559370720.4323)
$usedTime = microtime(true) - $startTime; //12.67

 

{ Result }

only get correct float time after add param true, without the True, it return a string(split time to two parts)