PHP TutorialLesson 17Free preview
PHP Switch
This lesson is part of PHP · All levels
Summary
The switch structure is used to select one of many options based on the same value, making it more concise than many if-elseifs. Each option is written with a case, and a break is used so that the execution does not fall on the next case. There are also default blocks that run when there's no matching case.
Key points
- Switch compares one variable with many case values
- Break stops execution after a case is completed
- Default executed if no case matches
- Without a break, the execution will fall through to the next case.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.