[Audio] SWITCH CASE. SWITCH CASE.
[Audio] Presented by L.Chitra. Presented by L.Chitra.
[Audio] 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). [Audio] Syntax Switch (expression).
[Audio] Here how it works: 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 expression. 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. $day = “Wednesday” switch ($day) In this example, since the value of $day is “Wednesday,” it will execute the code in the second case block, and you’ll see “It’s hump day!” printed..
[Audio] Thank you. Thank you.