Home » » intval

intval

Written By 1 on Sunday, September 30, 2012 | 6:51 PM

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

Get the integer value of a variable

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.


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

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


Building a CMS with PHP part 65 - intval function

0 Comment:

Post a Comment