$intVariable = intval( $unknownVariable );
// or:
$intVariable = (int)$unknownVariable;You can cast with this function every php variable, like double. Remember that php can throw a error or warning, especially if variable is not set
PHP Coding tips & tricks. Function & error explanation, coding style, how tos etc. Short notes posted directly from developer work environment.
PHP Coding Tips
Showing posts with label int. Show all posts
Showing posts with label int. Show all posts
Tuesday, August 7, 2012
How to convert string to int, or other variable to integer
To convert string to int in PHP you can use casting or intval() function. See example:
Subscribe to:
Posts (Atom)