Open In App

How to use a switch case 'or' in PHP?

Last Updated : 11 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report
Problem: How to use a switch case 'or' in PHP? Solution: This can be achieved in 2 ways. They are as follows: Method 1: Without using break keyword in one of the switch case. Example: php
<?php
$option = 1;
switch ($option)
{
    case 1:
    case 2:
        echo "The option is either 1 or 2.";
    break;
}
?>
Output:
The option is either 1 or 2.
Method 2: Using or operator in switch case. Example: php
<?php
$option = 1;
switch ($option) {
    case ($option == 1 || $option == 2):
        echo 'The option is either 1 or 2';
        break;
}
?>
Output:
The option is either 1 or 2
Reference: https://www.php.net/manual/en/control-structures.switch.php

Similar Reads