Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP Switch Statement

PHP Switch Statement


The switch statement is used to execute different actions based on multiple different conditions.


PHP Switch Statement

If you wantto selectively execute one of several code blocks, please use the switch statement.

Syntax

Parameter Description:

**How it works:** First, a simple expression n(usually a variable) is evaluated once. The value of the expression is compared with the value of each case in the structure. If a match exists, the code associated with that case is executed. After the code is executed, use break to prevent the code from jumping into the next case and continuing execution.default statement is used to execute when there is no match (i.e., no case is true).

Example

Run Example »