note 73651 added to function.settype
| From: | sneskid at hotmail dot com | Date: | Mon, 05 Mar 2007 22:57:35 +0000 |
| Subject: | note 73651 added to function.settype | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-124125@lists.php.net to get a copy of this message | ||
In response to the guy who was having troubles with leading zeros and wrote the convertToInt
function.
I benchmarked it and it is faster to just use base_convert than ltrim & friends.
base_convert also has a lower "first time call" cost than ltrim (this could be related to
server settings).
It's about 2/3 that of ltrim.
If you only use this type of conversion once per script then it's far more beneficial to use
base_convert.
The average values listed are ignoring the first time call costs.
<?php
$t = '0100';
// avg: 0.0000025 (0.0000036 wrapped as a function)
$x = base_convert($t, 10, 10);
// avg: 0.0000028 (0.0000039 wrapped as a function)
$x = 0+ltrim($t,'0');
?>
----
Server IP: 69.147.83.197
Probable Submitter: 74.118.123.241
----
Manual Page -- http://www.php.net/manual/en/function.settype.php
Edit -- https://master.php.net/note/edit/73651
Del: integrated -- https://master.php.net/note/delete/73651/integrated
Del: useless -- https://master.php.net/note/delete/73651/useless
Del: bad code -- https://master.php.net/note/delete/73651/bad+code
Del: spam -- https://master.php.net/note/delete/73651/spam
Del: non-english -- https://master.php.net/note/delete/73651/non-english
Del: in docs -- https://master.php.net/note/delete/73651/in+docs
Del: other reasons-- https://master.php.net/note/delete/73651
Reject -- https://master.php.net/note/reject/73651
Search -- https://master.php.net/manage/user-notes.php