Saturday, August 7, 2010

Typecasting to int or float

easy solution is
$val = $val + 0;
And PHP will take care of the rest.
If you want to ensure that the variable is integer is_numeric is the way to go. is_int and is_float will be of little help here.
Also note that will always evaluate to true
if ((int)$value == $value)
that is because of the internal typecasting of the equality operator

No comments:

Post a Comment