note 99576 added to function.microtime

From: Date: Wed, 25 Aug 2010 07:59:58 +0000
Subject: note 99576 added to function.microtime
Groups: php.notes 
Request: Send a blank email to php-notes+get-172033@lists.php.net to get a copy of this message
@Paul You have to remember that PHP interprets strings as zero if used in mathematical expressions (unless they start with a parseable number, i.e. "1234abcd"). So when you try to concatenate "Took:" and $end you get a string which when followed by a minus operator is interpreted as zero. So the result is -$start. Finally, that's interpreted as a string and concatenated with " seconds". To avoid this you can just enclose the math part in parentheses so that the subtraction is given priority: <?echo 'Took:'.($end-$start).' seconds';?> ---- Server IP: 69.147.83.197 Probable Submitter: 213.147.113.11 ---- Manual Page -- http://www.php.net/manual/en/function.microtime.php Edit -- https://master.php.net/note/edit/99576 Del: integrated -- https://master.php.net/note/delete/99576/integrated Del: useless -- https://master.php.net/note/delete/99576/useless Del: bad code -- https://master.php.net/note/delete/99576/bad+code Del: spam -- https://master.php.net/note/delete/99576/spam Del: non-english -- https://master.php.net/note/delete/99576/non-english Del: in docs -- https://master.php.net/note/delete/99576/in+docs Del: other reasons-- https://master.php.net/note/delete/99576 Reject -- https://master.php.net/note/reject/99576 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#172033) next »