PHP Switch Statement With Example

aimtocode

Switch statement

selects one of many blocks of code to be executed

To select one of many blocks of code to be executed, use the Switch statement. The switch statement is used to avoid long blocks of if..elseif..else code.

The switch statement works in an unusual way. First it evaluates given expression then seeks a label to match the resulting value.

If a matching value is found then the code associated with the matching label will be executed or if none of the labels match then statement will execute any specified default code.


Syntax:



Example:




Result:



  Today is Monday



Read Also:


aimtocode