PHP intval() Function
intval() The function is used to get the integer value of a variable.
intval() The function returns the integer value of the variable var by converting using the specified base (default is decimal). intval() cannot be used on objects, otherwise it will produce 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 value to be converted to an integer.
- $base: the base used for the conversion.
If base is 0, the base to use is determined by detecting the format of var:
- If the string includes the prefix "0x" (or "0X"), use hexadecimal (hex); otherwise,
- if the string starts with "0", use octal; otherwise,
- use decimal.
Return Value
On success, returns the integer value of var; on failure, returns 0. An empty array returns 0, a non-empty array returns 1.
The maximum value depends on the operating system. On a 32-bit system, the maximum signed integer range is -2147483648 to 2147483647. For example, on such a system, intval('1000000000000') returns 2147483647. On a 64-bit system, the maximum signed integer value is 9223372036854775807.
A string may return 0, depending on the leftmost character of the string.
Available PHP Functions