Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP intval() Function

PHP intval() Function

PHP Available FunctionsAvailable PHP Functions

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:

If base is 0, the base to use is determined by detecting the format of var:

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.

Example

Example

PHP Available FunctionsAvailable PHP Functions