The FILTER_VALIDATE_INT constant validates value as integer.
Options and flags
min_range − The minimum integer value
max_range − The maximum integer value
FILTER_FLAG_ALLOW_OCTAL − Allows octal number values
FILTER_FLAG_ALLOW_HEX − Allows hexadecimal number values
Return
The FILTER_VALIDATE_INT constant does not return anything.
Example
<?php
$int = 110;
$var = 3.5;
var_dump(filter_var($var, FILTER_VALIDATE_FLOAT));
if (filter_var($int, FILTER_VALIDATE_INT)) {
echo("Integer Variable");
} else {
echo("Not an Integer Variable");
}
?>Output
The following is the output.
float(3.5) Integer Variable
Let us see another example.
Example
<?php
$int = 5;
$min = 1;
$max = 20;
if (filter_var($int, FILTER_VALIDATE_INT, array("options" => array("min_range"=>$min, "max_range"=>$max))) === false) {
echo("Range not accepted!");
} else {
echo("Accepted range!");
}
?>Output
Here is the output.
Accepted range!