Easy Tutorial
❮ Php Date Func String Str Word Count ❯

PHP intval() Function

PHP Available Functions

The intval() function is used to get the integer value of a variable.

The intval() function returns the integer value of the variable var by using the specified base for conversion (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 used is determined by the format of var:

Return Value

Returns the integer value of var on success, or 0 on failure. 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') will return 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.

Examples

<?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
?>

PHP Available Functions

❮ Php Date Func String Str Word Count ❯