PHP Tutorial

A web server programming language.

PHP Switch

PHP switch Statement

The switch statement is used to perform different actions based on different conditions. It is used to select one of many blocks of code to be executed.

Syntax:

switch (n) {
  case label1:
    code to be executed if n=label1;
    break;
  case label2:
    code to be executed if n=label2;
    break;
  default:
    code to be executed if n is different from all labels;
}

Try It Yourself

Edit the code below and click Run to see the result live.

Source Code
Result
Topics