Switch Case in PHP – website development

In this video

This tutorial is about Switch Case in PHP. In our last lecture we learned about For & Foreach loop in PHP. If you haven’t watched it yet then here is the link of tutorial http://tutorialhive.net/2018/10/31/for-foreach-loop-in-php/ .

 Switch Case in PHP

In this tutorial we will learn about Switch Case in PHP.

Switch Case SYNTAX

Switch statement allows you to execute code conditionally. It compares a variable or an expression against many different values and execute code according to value it equals to. If you want to select one of many blocks of code to be executed, use the Switch statement.

switch (n) {

case label1:

code to be executed if n=label1;


case label2:

code to be executed if n=label2;


case label3:

code to be executed if n=label3;






$favcolor = “red”;


switch ($favcolor) {

    case “red”:

        echo “Your favorite color is red!”;


    case “blue”:

        echo “Your favorite color is blue!”;


    case “green”:

        echo “Your favorite color is green!”;



        echo “Your favorite color is neither red, blue, nor green!”;



Output: Your favorite color is red!

Switch Case in PHP tutorial end here. In next tutorial we will learn about how to find Random Element from Array in PHP. If you have any queries you can ask us on our Facebook page link is given below, Thank you for watching us.


Tutorial Hive’s mission is to provide quality education to all our community. Tutorial Hive’s mission is to provide free education to all those who cannot afford BIG FEE of institutes. We aim specifically to empower youth to understand programming related knowledge which further helps the society to reduce complex problems through applications. Why Tutorial Hive? We not only provide the theoretical knowledge but also provide the actual implementation with working sample applications. Tutorial Hive cannot achieve its mission without the help of our community. So, please if you think you can help in any manner feel free to contact us. Or if you see any mistake in our content which can be modified/corrected then please leave us a message

We are always open for suggestions.

Facebook: www.facebook.com/hbss2015

Subscribe on YouTube: https://www.youtube.com/channel/UCOUy6kTpedj7s6HOqM0c08w


Follow us on Social Media

You might be interested in


Your email address will not be published. Required fields are marked *