English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
intval() The function is used to get the integer value of the variable.
intval() The PHP function converts the variable var to an integer value using the specified base (default is decimal), and returns the integer value of the variable var. intval() cannot be used for objects, otherwise it will produce an E_NOTICE error and return 1.
PHP 4, PHP 5, PHP 7
int intval ( mixed $var [, int $base = 10 ] )
Parameter description:
If base is 0, the format of var is detected to determine the used base:
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. 32 bit system, the maximum signed integer range is -2147483648 to 2147483647. For example, on such a system, intval('1000000000000 2147483647.64 On a bit system, the maximum signed integer value is 9223372036854775807.
A string may return 0, although it depends on the character at the leftmost position of the string.
<?php echo intval(42); // 42 echo intval(4.2); // 4 echo intval('42'); // 42 echo intval('+42'); // 42 echo intval('-42'); // -42 echo intval(042); // 34 echo intval('042'); // 42 echo intval(1e10); // 1410065408 echo intval('1e10'); // 1 echo intval(0x1A); // 26 echo intval(42000000); // 42000000 echo intval(420000000000000000000); // 0 echo intval('420000000000000000000'); // 2147483647 echo intval(42, 8); // 42 echo intval('42', 8); // 34 echo intval(array()); // 0 echo intval(array('foo', 'bar')); // 1 ?>