Validating an Integer Range in PHP


Check if a variable is an integer within a specific range using filter_var() with FILTER_VALIDATE_INT and a range option.

Source Code

$options = [
    "options" => [
        "min_range" => 1,
        "max_range" => 100
    ]
];
$var = 50;
if (filter_var($var, FILTER_VALIDATE_INT, $options) !== false) {
    echo "The variable is within the range.";
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments