Is it possible to use a switch statement with a range of values in PHP?
In PHP, the switch statement does not support a range of values directly. However, you can achieve a similar functionality by using a series of case statements to cover the desired range of values. This can be done by checking if the value falls within the specified range in each case statement and executing the corresponding code block.
$value = 5;
switch (true) {
case ($value >= 1 && $value <= 5):
echo "Value is between 1 and 5";
break;
case ($value >= 6 && $value <= 10):
echo "Value is between 6 and 10";
break;
default:
echo "Value is not in the specified range";
}