note 41172 deleted from function.gettimeofday by didou

From: Date: Tue, 06 Jul 2004 21:25:47 +0000
Subject: note 41172 deleted from function.gettimeofday by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-72796@lists.php.net to get a copy of this message
Note Submitter: php@frangoassado.org ---- <?php function get_timer() { $t=gettimeofday(); return (double)($t['sec'].'.'.$t['usec']); } ?> This function has a bug. When $t['usec'] goes from 9 to 10, the returned double goes from xxxx.9 to xxxx.1, clearly not what was expected. The correct function should be something like <?php function get_timer() { $t=gettimeofday(); return (double)($t['sec'].'.'.sprintf("%06d", $t['usec'])); } ?>

« previous php.notes (#72796) next »