PHP intval() Function

The intval() Function in PHP is used to get the integer value for the given variable. This function should not be used on objects. Else it will emit an E_NOTICE level error and return 1.

Syntax

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

Parameter

var(required)- This parameter represents the scalar value that is converted to an integer.

base(optional)- This parameter signifies the base for the conversion. If the base is 0, the base is determined by var, and the possible base values are as follows:

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

Return

This function returns the integer value of the parameter ‘var’ on success, or 0 on failure. If var is initialized with empty arrays, it returns 0, for non-empty arrays, it returns 1.

Example 1

 

Output

Variable: 237.43
After the intval() function...
Integer value: 237  

Example 2

  

Output

Variable: 291
After the intval() function...
Integer value: 291  

Example 3

 

Output

Variable: Hello World
After the intval() function...
Integer value: 0  

Example 4




Output

PHP Parse error:  Invalid numeric literal in /workspace/Main.php on line 3