How to use a switch case 'or' in PHP


Question

Is there a way of using an 'OR' operator or equivalent in a PHP switch?

For example, something like this:

switch ($value) {

    case 1 || 2:
        echo 'the value is either 1 or 2';
        break;
}
1
210
7/14/2019 4:04:41 PM

switch ($value)
{
    case 1:
    case 2:
        echo "the value is either 1 or 2.";
    break;
}

This is called "falling through" the case block. The term exists in most languages implementing a switch statement.

475
12/20/2016 11:11:10 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon