note 99576 deleted from function.microtime by danbrown
| From: | danbrown@php.net | Date: | Wed, 25 Aug 2010 14:03:39 +0000 |
| Subject: | note 99576 deleted from function.microtime by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-172055@lists.php.net to get a copy of this message | ||
Note Submitter: Zoran
----
@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';?>