How can one ensure that a number input in PHP falls within a specific range?

To ensure that a number input in PHP falls within a specific range, you can use an if statement to check if the input is within the desired range. If the input is outside the range, you can set it to the minimum or maximum value of the range accordingly.

$input = 15;
$min = 10;
$max = 20;

if ($input < $min) {
    $input = $min;
} elseif ($input > $max) {
    $input = $max;
}

echo $input; // Output will be 15