intval
Function • Params and return types changed in PHP 8.0
Get the integer value of a variable.
intval Function synopsis
intval(mixed $value, int $base = 10): int
Parameters
$value
Typemixed
The scalar value being converted to an integer
$base
OptionalTypeintDefault value10
The base for the conversion
Return value
Typeint
The integer value of $value on success, or 0 on
failure. Empty arrays return 0, non-empty arrays return 1.
The maximum value depends on the system. 32 bit systems have a
maximum signed integer range of -2147483648 to 2147483647. So for example
on such a system, intval('1000000000000') will return
- The maximum signed integer value for 64 bit systems is
-
Strings will most likely return 0 although this depends on the leftmost characters of the string. The common rules of integer casting apply.
Changes to the intval Function
PHP 8.0
- Return type added:
int - Parameter name of parameter #1 changed:
$varto$value - Parameter type added for parameter #1 (
$value):mixed - Parameter type added for parameter #2 (
$base):int - Parameter default value added for position #2 (
$base):10
- intval($var, $base)
+ intval(mixed $value, int $base = 10): int intval Function Availability
intval Function Availability| PHP Version | Availability |
|---|---|
| PHP 8.6Upcoming Release | Yes |
| PHP 8.5Supported (Latest) | Yes |
| PHP 8.4Supported | Yes |
| PHP 8.3Security-Fixes Only | Yes |
| PHP 8.2Security-Fixes Only | Yes |
| PHP 8.1Unsupported | Yes |
| PHP 8.0Unsupported | Yes |
| PHP 7.4Unsupported | Yes |
| PHP 7.3Unsupported | Yes |
| PHP 7.2Unsupported | Yes |
| PHP 7.1Unsupported | Yes |
| PHP 7.0Unsupported | Yes |
| PHP 5.6Unsupported | Yes |
| PHP 5.5Unsupported | Yes |
| PHP 5.4Unsupported | Yes |
| PHP 5.3Unsupported | Yes |