If you must use ||
with switch
then you can try :
$v = 1;
switch (true) {
case ($v == 1 || $v == 2):
echo 'the value is either 1 or 2';
break;
}
If not your preferred solution would have been
switch($v) {
case 1:
case 2:
echo "the value is either 1 or 2";
break;
}
The issue is that both method is not efficient when dealing with large cases ... imagine 1
to 100
this would work perfectly
$r1 = range(1, 100);
$r2 = range(100, 200);
$v = 76;
switch (true) {
case in_array($v, $r1) :
echo 'the value is in range 1 to 100';
break;
case in_array($v, $r2) :
echo 'the value is in range 100 to 200';
break;
}