If i have sting like
$str = '515';
I want convert it to int, is better use
$str = $str * 1;
than use
$str = intval($str);
which performance is better?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
When you use
$str = $str * 1,$strwill 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.