PHP switch Statement Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 1 Likes Like Report 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: 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. PHP <?php $x = 2; switch ($x) { case 1: printf("Choice is 1"); break; case 2: printf("Choice is 2"); break; case 3: printf("Choice is 3"); break; default: printf("Choice other than 1, 2 and 3"); } ?> OutputChoice is 2 Example 2: PHP <?php $n='C'; switch($n) { case 'A': case 'B': printf("A and B\n"); break; case 'C': case 'D': printf("C and D\n"); break; default:printf("Alphabet is greater than D\n"); } ?> OutputC and D Reference: https://www.php.net/manual/en/control-structures.switch.php Create Quiz Comment V vkash8574 Follow 1 Improve V vkash8574 Follow 1 Improve Article Tags : Web Technologies PHP PHP-basics Explore BasicsPHP Syntax4 min readPHP Variables5 min readPHP | Functions6 min readPHP Loops4 min readArrayPHP Arrays5 min readPHP Associative Arrays4 min readMultidimensional arrays in PHP5 min readSorting Arrays in PHP4 min readOOPs & InterfacesPHP Classes2 min readPHP | Constructors and Destructors5 min readPHP Access Modifiers4 min readMultiple Inheritance in PHP4 min readMySQL DatabasePHP | MySQL Database Introduction4 min readPHP Database connection2 min readPHP | MySQL ( Creating Database )3 min readPHP | MySQL ( Creating Table )3 min readPHP AdvancePHP Superglobals6 min readPHP | Regular Expressions12 min readPHP Form Handling4 min readPHP File Handling4 min readPHP | Uploading File3 min readPHP Cookies9 min readPHP | Sessions7 min read Like