SWITCH CASE.
Presented by L.Chitra.
Introduction In PHP,a Switch statement is used to perform different actions based on the value of a given expression. It's a way to simplify a series of if-elseif-else statements when you need to make decisions based on a single value..
Syntax Switch (expression) { case valuel: break; case value2: break; default:.
Here how it works: 1. 2. 3. 4. 6. The switch keyword initiates the switch statement. The expression you want to evaluate is placed within the parentheses after the switch keyword. The case keyword is followed by a value that you want to compare with the expressron. If the expression matches a case value, the code inside that case block is executed. You can have multiple case blocks. The break statement is used to exit the switch statement after a case is executed. If you omit it, the execution will continue to the next case, which might not be what you want. You can also use a default case, which is executed if none of the case values match the expression..
Example Sday = "Wednesday" switch (Sday) { case "Monday": echo "It's the start of the workweek."; break; case "Wednesday": echo "It's hump day!"• break; default: echo "It's some other day."; In this example, since the value of Sday is "Wednesday," it will execute the code in the second case block, and you'll see "It's hump day!" printed..
Thank you.