The function intval() gets the integer value of a variable.
int intval (mixed $value, int $base = 10 )
Sr.No | Parameter & Description |
---|---|
1 |
value Mandatory. This parameter serves as the variable which needs to be converted to its integer value. |
2 |
base Optional. It has no effect unless the value parameter is a string. If base is not specified or 0, the base used is determined by the format of value:
|
This function returns interger value of value on success or 0 on failure. Empty arrays return 0, non-empty arrays return 1.
PHP 4 and above
Following example demonstrates return values with different types of variables −
<?php echo intval(100).'<br>'; //100 echo intval(100.11).'<br>'; //100 echo intval('100').'<br>'; //100 echo intval(+100).'<br>'; //100 echo intval(-100).'<br>'; //-100 echo intval(0104).'<br>'; //68 echo intval('0104').'<br>'; //104 echo intval(1e10).'<br>'; //10000000000 echo intval('1e10').'<br>'; //10000000000 echo intval(0x2B).'<br>'; //43 echo intval(10400000).'<br>'; //10400000 echo intval(420000000000000000000).'<br>';//-4275113695319687168 echo intval('420000000000000000000').'<br>';//9223372036854775807 echo intval(11, 12).'<br>'; //11 echo intval('11', 12).'<br>'; //13 ?>
This will produce following result −
100 100 100 100 -100 68 104 10000000000 10000000000 43 10400000 -4275113695319687168 9223372036854775807 11 13