How to use a PHP Switch Case with Multiple Conditions?


In this tutorial, we will examine the syntax, parameters, differences from the if statement, and provide you with a variety of examples to showcase the versatility of the PHP switch case statement.


In the world of PHP programming, the switch case statement serves as a powerful tool for handling multiple conditions within your code. While the if statement is a commonly used construct, the switch case offers a more concise and structured way to manage complex branching logic.

Syntax and Parameters

 The PHP switch case statement follows a straightforward syntax:


switch ($variable) {

case value1:

     // Code to execute for value1


case value2:

     // Code to execute for value2


// additional cases


     // Code to execute if no case matches


Here, $variable represents the value you are evaluating, and each case corresponds to a potential value of the variable. The break statement terminates the switch case block, preventing fall-through to subsequent cases.

Note: Like break, the continue statement also applies to switch. Use continue 2 to move to the following iteration of the outer loop if there is a switch inside a loop.

How to work?

The switch statement works step by step. It starts running when it finds a case that matches the switch expression’s value. PHP keeps running the code until the switch section ends or it encounters a “breakstatement. If you forget to use “break” at the end of a case, PHP will keep running code from the next case.


// Represents Wednesday

$dayNumber = 3; 

switch ($dayNumber) {

case 1:

     echo "It's Monday!";


case 2:

     echo "It's Tuesday!";


case 3:

     echo "It's Wednesday!";

     // No "break" here, so it will continue to the next case

case 4:

     echo "It's Thursday!";



     echo "It's a weekend day!";



It's Wednesday!
It's Thursday!


Let us explore some practical examples to illustrate the usage of the PHP switch case with multiple conditions:

Example 1#


$score = 85;

switch ($score) {

case ($score >= 90):

     echo "A";


case ($score >= 80):

     echo "B";


case ($score >= 70):

     echo "C";



     echo "D";




Example 2#


//Day of the Week:

$day = "Wednesday";

switch ($day) {

case "Monday":

case "Tuesday":

case "Wednesday":

case "Thursday":

case "Friday":

     echo "Weekday";


case "Saturday":

case "Sunday":

     echo "Weekend";



     echo "Invalid day";




Frequently Asked Questions

Q: How to use multiple switch case in PHP?

Ans: To use multiple switch cases in PHP, follow these steps: define the variable to be evaluated, use the switch statement, and provide cases for different values. Each case should contain the desired code block, and do not forget the break statement to prevent fall-through.

Q: Can you use a switch case with multiple conditions?

Ans: Switch cases in PHP are primarily designed for single-value comparisons. While you cannot directly use multiple conditions within a single case, you can achieve similar results by nesting switch statements or combining the cases under the same code block.

Q: What is the switch case in PHP with condition?

Ans: In PHP, the switch case is a control structure used to compare a variable against multiple values. When a match is found, the corresponding code block executes. The “with condition” implies that you can utilize the evaluated value to determine the case, allowing for flexible control flow.

Q: Can we use switch case in PHP?

Ans: Yes, you can use the switch case in PHP. It is a powerful tool for simplifying complex decision-making based on the value of a variable. Switch cases improve code readability and efficiency, especially when dealing with multiple possible values for comparison.


In the world of PHP programming, overcoming the switch case statement with multiple conditions can greatly improve your ability to handle complex decision-making processes. Its structured syntax, along with the ability to handle different cases efficiently, make it an invaluable tool for writing neat and organized code. 

%d bloggers like this: