|Lessons||PHP Switch Statement|
code to be executed if expression = label1;
code to be executed if expression = label2;
code to be executed if expression is different from both label1 and label2;
This is how it works: • The expression written inside the switch statement i.e. switch(expression) is evaluated. This could also be a variable.
• The value of the expression is compared with the values of each of the case labels.
• If there is a match, the code associated with that case is executed.
• After the code of the match case is executed, break is used to stop the code from running into the next case.
• The default statement is used if a matching case is not found.
$exp = 2;
echo "Number 1";
echo "Number 2";
echo "Number 3";
Next: PHP Defining Functions 1