970_90

Monday, 1 October 2012

intval - Get Integer value from string in PHP

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.

<?phpecho intval(42);                      // 42echo intval(4.2);                     // 4echo intval('42');                    // 42echo intval('+42');                   // 42echo intval('-42');                   // -42echo intval(042);                     // 34echo intval('042');                   // 42echo intval(1e10);                    // 1410065408echo intval('1e10');                  // 1echo intval(0x1A);                    // 26echo intval(42000000);                // 42000000echo intval(420000000000000000000);   // 0echo intval('420000000000000000000'); // 2147483647echo intval(428);                   // 42echo intval('42'8);                 // 34echo intval(array());                 // 0echo 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

No comments:

Post a Comment