How do you change a string into an integer in PHP?

ed_man118

New member
I need to change the string "32" into the integer 32. I know that in a lot of cases, this will happen automatically if you need it to, but mine is not one of those cases. Thank you for your time.
 
If the string does not contain any of the characters '.', 'e', or 'E' and the numeric value fits into integer type limits (as defined by PHP_INT_MAX), the string will be evaluated as an integer.

Alternatively there is the intval function:

<?php
$string = "32";
$newstring = intval($string);

echo $newstring; // output: 32 (integer value of string var)
?>
 
Back
Top