Home > Article > Backend Development > What does intval mean in php
In PHP, intval means to get the integer value of a variable. It is a function that can convert other types of variables into integer types; this function converts by using the specified base base (the default is decimal), Return the integer value of the variable, the syntax is "intval($var,$base)".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
In php, the intval function can obtain the variable Integer value. (Generally, the intval function is used for data type conversion, which can convert a string into an integer type.)
intval() function returns the integer value of the 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.
Syntax:
int intval ( mixed $var [, int $base = 10 ] )
Parameter description:
$var: The quantity value to be converted to integer.
#$base: The base used for conversion.
If base is 0, the base used is determined by detecting the format of var:
If the string includes "0x" ( or "0X"), use hexadecimal (hex); otherwise,
If the string starts with "0", use octal (octal); otherwise,
Decimal will be used.
Return value
Returns the integer value of var on success, and returns 0 on failure. An empty array returns 0, a non-empty array returns 1.
The maximum value depends on the operating system. The maximum signed integer range on 32-bit systems is -2147483648 to 2147483647. For example, on such a system, intval('1000000000000') would return 2147483647. On a 64-bit system, the maximum signed integer value is 9223372036854775807.
String may return 0, although it depends on the leftmost character of the string.
Example:
<?php echo intval(42)."<br>"; // 42 echo intval(4.2)."<br>"; // 4 echo intval('42')."<br>"; // 42 echo intval('+42')."<br>"; // 42 echo intval('-42')."<br>"; // -42 echo intval(042)."<br>"; // 34 echo intval('042')."<br>"; // 42 echo intval(1e10)."<br>"; // 1410065408 echo intval('1e10')."<br>"; // 1 echo intval(0x1A)."<br>"; // 26 echo intval(42000000)."<br>"; // 42000000 echo intval(420000000000000000000)."<br>"; // 0 echo intval('420000000000000000000')."<br>"; // 2147483647 echo intval(42, 8)."<br>"; // 42 echo intval('42', 8)."<br>"; // 34 echo intval(array())."<br>"; // 0 echo intval(array('foo', 'bar'))."<br>"; // 1 ?>
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What does intval mean in php. For more information, please follow other related articles on the PHP Chinese website!