I was wondering what is the best way to typecast a value from one type to another.
Which variant should we use:
intval($value);settype($value, 'int')(int)$value
All of them produce same result.
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.
saves one function call compares to
intval($value)andsettype($value, 'int').And
(int)$valueis clean enough, so I prefer this way.When you need to use
intval($value)is that when you need to use the specified base for the conversion (the default is base 10). intval accepts a second parameter for the base for the conversion.