In this article, you will learn how to get the integer value of a variable in PHP. The intval() function in PHP returns the integer value of a variable.
what is the syntax of the INTVAL() function in php?
intval(variable, base);
Parameters | Details |
---|---|
variable | Required. Specifies the variable to check |
base | Optional. Specifies the base to use for the conversion. Only has effect if variable is a string. Default base is 10 |
examples of the INTVAL() function
Example 1. In this example, we return the integer value of different variables.
<?php
$a = 32;
echo intval($a) . "<br>";
$b = 3.2;
echo intval($b) . "<br>";
$c = "32.5";
echo intval($c) . "<br>";
$d = array();
echo intval($d) . "<br>";
$e = array("red", "green", "blue");
echo intval($e) . "<br>";
?>