VOOZH about

URL: https://www.geeksforgeeks.org/php/php-switch-statement/

⇱ PHP switch Statement - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

PHP switch Statement

Last Updated : 23 Jul, 2025

The switch statement is similar to the series of if-else statements. The switch statement performs in various cases i.e. it has various cases to which it matches the condition and appropriately executes a particular case block. It first evaluates an expression and then compares it with the values of each case. If a case matches then the same case is executed. 

To use the switch, we need to get familiar with two different keywords namely, break and default.

  • break: The break statement is used to stop the automatic control flow into the next cases and exit from the switch case.
  • default: The default statement contains the code that would execute if none of the cases match.

Flowchart of switch statement:

👁 Image
 

Syntax:

switch(expression)
{
 case val1:
 // Code Statement
 break;
 case val2:
 // Code statement
 break;
 ...
 
 default:
 // Code Statement
}

Example 1: The following code demonstrates the switch statement.


Output
Choice is 2

Example 2:


Output
C and D

Reference: https://www.php.net/manual/en/control-structures.switch.php

Comment
Article Tags: