PHP switch Statement Last Updated : 15 Feb, 2023 Summarize Comments Improve Suggest changes Share Like Article 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 Comment More infoAdvertise with us Next Article PHP switch Statement V vkash8574 Follow Improve Article Tags : Web Technologies PHP PHP-basics Similar Reads PHP goto Statement The goto statement is used to jump to another section of a program. It is sometimes referred to as an unconditional jump statement. The goto statement can be used to jump from anywhere to anywhere within a function. Flowchart of goto statement: Syntax: statement_1; if (expr) goto label; statement_2; 1 min read Getting Started with PHP PHP (Hypertext Preprocessor) is a powerful scripting language widely used for web development. Whether you're looking to create dynamic web pages, handle form data, interact with databases, or build web applications, PHP has you covered. In this guide, we'll take you through the basics of PHP, cover 7 min read PHP continue Statement The continue statement is used within a loop structure to skip the loop iteration and continue execution at the beginning of condition execution. It is mainly used to skip the current iteration and check for the next condition. The continue accepts an optional numeric value that tells how many loops 1 min read PHP Syntax PHP, a powerful server-side scripting language used in web development. Itâs simplicity and ease of use makes it an ideal choice for beginners and experienced developers. This article provides an overview of PHP syntax. PHP scripts can be written anywhere in the document within PHP tags along with n 4 min read PHP | startsWith() and endsWith() Functions startsWith() Function The StartsWith() function is used to test whether a string begins with the given string or not. This function is case insensitive and it returns boolean value. This function can be used with Filter function to search the data. Syntax bool startsWith( string, startString ) Param 3 min read Like