开发者

performance about string convert to int

If i have sting 开发者_Python百科like

$str = '515';

I want convert it to int, is better use

$str = $str * 1;

than use

$str = intval($str);

which performance is better?


When you use $str = $str * 1, $str will first cast into an integer then plus 1, so it is one step more.

Besides, $str = intval($str); is much more readable than $str = $str * 1;,

You could also just use casting by $str = (int)$str.


Casting the value using (int) should be the quickest option as intval() invokes a function (which has a small performance overhead)

$str = (int)$str;

see http://wiki.phpbb.com/Best_Practices:PHP#Typecasting for more information

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜