PHP Intval () function

PHP

Syntax:
int intval ($var, $base)
Parameters:This function takes two parameters, of which one is required and the other - optional. The parameters are described below:
  • $var:This is a required parameter and serves as a variable to be converted to its integer value.
  • $base:an optional parameter that specifies the base to convert $var to its corresponding integer. If $base is not specified.
    • If the prefix is ​​0x (or 0X), the base is assumed to be 16.
    • If it starts with 0, the base is assumed to be 8
    • Otherwise, it is based on 10.
Returned value:returns the corresponding integer value $var.Examples :
Input: $var = '120', $base = 8 Output: 80 Input: $var = 0x34 Output: 52 Input: $var = 034 Output : 28
The following programs illustrate the use of the intval() function in PHP:Program 1: $var = '7.423' ; $int_value = intval ( $var ); echo $int_value ; ?> Exit:
7
Program 2: $var = 0x423; $int_value = intval ( $var ); echo $int_value ; ?> Exit:
1059
Program 3: $var = "64" ; echo intval ( $var ). "" . intval ( $var , 8);  
?>
Exit:
64 52 
Link: http://php.net /manual/en/function.intval.php