In PHP, the intval() function can obtain the integer value of a variable and is often used for data type conversion to convert string type variables into integer types; the specific usage syntax is "intval($ var[,$base])".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
intval() function is used to obtain the integer of the variable value. Syntax format:
int intval ( mixed $var [, int $base = 10 ] )
$var: The quantity value to be converted to integer.
#$base: The base used for conversion.
If base is 0, determine the base used by detecting the format of var:
If the string includes "0x" (or "0X") Prefix, use hexadecimal (hex); otherwise,
If the string starts with "0", use octal (octal); otherwise,
Decimal will be used.
The intval() function is often used for data type conversion to convert string type variables into integer types.
intval() function returns the integer value of variable var by using the specified base conversion (default is decimal). intval() cannot be used with object, otherwise an E_NOTICE error will be generated and 1 will be returned.
Example: Convert a string to an integer
<?php header("Content-type:text/html;charset=utf-8"); $str = '123.456abc'; $int = intval($str); echo '变量 $int 的类型为:'.gettype($int).'<br>'; var_dump($int); ?>
Output result:
Recommended Study: "PHP Video Tutorial"
The above is the detailed content of How to use php intval(). For more information, please follow other related articles on the PHP Chinese website!