Tuesday, 20 January 2015

intval Function in PHP

PHP intval function is used to get an integer value from the given input value. It returns the integer value on success and 0 on failure.

Syntax:


intval(var_name, base)

var_name - Variable name
base - Base conversion ( Default 10 )

Example:


<?php
echo intval(28)."<br />";
echo intval(28,8)."<br />";
echo intval(28.1)."<br />";
echo intval(+28)."<br />";
echo intval(-28)."<br />";
echo intval(0x1B)."<br />";
echo intval(1e30)."<br />";
?>

Result


28
28
28
28
-28
27
0

In the above example, the given input is converted to integer value.
Note: The Prefix "0x" represents the Hexadecimal values(Base 16).
   The Prefix "0" represents the Octal values(Base 8).

0 comments:

Post a Comment