Anonymous user / 54.224.43.79 Log In Register
?
Wallet: 3.00
Daily Credits:
1.20 / 1.20

PHP Functions Online


intval

(PHP 4, PHP 5)

intvalGet the integer value of a variable

int intval(mixed $var[, int $base = 10])

Checkout ? #

Item Description Item Price Your Price
Total

Preview #

${{ variable.param.name }} = {{ variable.param|getValue:variable.form:true }};
{{ call.result}} = ;

Description #

int intval ( mixed $var [, int $base = 10 ] )

Returns the integer value of var, using the specified base for the conversion (the default is base 10). intval() should not be used on objects, as doing so will emit an E_NOTICE level error and return 1.

Parameters #

var

The scalar value being converted to an integer

base

The base for the conversion

Note:

If base is 0, the base used is determined by the format of var:

  • if string includes a "0x" (or "0X") prefix, the base is taken as 16 (hex); otherwise,
  • if string starts with "0", the base is taken as 8 (octal); otherwise,
  • the base is taken as 10 (decimal).

Return Values #

The integer value of var on success, or 0 on failure. Empty arrays return 0, non-empty arrays return 1.

Examples #

Example #1 intval() examples

The following examples are based on a 32 bit system.

<?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(428);                   // 42
echo intval('42'8);                 // 34
echo intval(array());                 // 0
echo intval(array('foo''bar'));     // 1
?>

Changelog #

Version Description
5.1.0 Throws E_NOTICE and returns 1, when an object is passed to var.

Notes #

Note:

The base parameter has no effect unless the var parameter is a string.

See Also #