View Full Version : How I make/convert a string (eg $x='346765' to $y=346765) to a number ...
lse123
12-02-2007, 05:45 PM
How I make/convert a string (eg $x='346765' to $y=346765) to a number in PHP ?
matak
12-02-2007, 06:15 PM
intval() (http://hr.php.net/intval)
$x = '12345';
$y = (int) $x;
$z = intval($x);
settype($x, 'int'); //note this is done to the original variable
(replace 'int' with 'float' if preferred)
A lot of the time you don't need do it explicitly though, PHP will do it for you when it's necessary.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.