PHP intval() Function
intval()The function is used to obtain the integer value of a variable.
intval()The function converts using the specified base (default is decimal) and returns the integer value of the variable var. intval() cannot be used on an object, otherwise it will generate an E_NOTICE error and return 1.
PHP 4, PHP 5, PHP 7
Syntax
int intval ( mixed $var [, int $base = 10 ] )
Parameter description:
- $var: The numeric value to convert to integer.
- $base: The base used for conversion.
If base is 0, the base is determined by detecting the format of var:
- If the string includes a "0x" (or "0X") prefix, use hexadecimal (hex); otherwise,
- If the string starts with "0", use octal; otherwise,
- Use decimal.
Return Value
Returns the integer value of var on success, and 0 on failure. An empty array returns 0, and a non-empty array returns 1.
The maximum value depends on the operating system. On 32-bit systems, the maximum signed integer range is -2147483648 to 2147483647. For example, on such a system, intval('1000000000000') will return 2147483647. On 64-bit systems, the maximum signed integer value is 9223372036854775807.
Strings may return 0, although it depends on the leftmost character of the string.
PHP Available Functions