More About PHP Switch Statements, Fall Through Explained, Exclude Break in PHP Switch Statements

If you ever wondered why we add breaks to switch statements in PHP and other programming languages, then this video, More About PHP Switch Statements, Fall Through Explained, Exclude Break in PHP Switch Statements, will help in answering that. This PHP programming lesson is based on Codecademy’s free programming course, Learn PHP, where we go over the PHP programming language. In the previous lesson, we looked at switch statements in PHP and how they basically work. In this lesson, we dive deeper into switch statements and learn more about the break keyword and when and why it is used. In this lesson, we learn that we are able to omit the break keyword when we don’t want the switch statement to stop executing. Sometimes you might want multiple values to return something, and in this case, we can omit the break keyword and that first case will run as well as the following case if the break is not declared. For example, you might want the words, “Friday”, “Saturday”, or “Sunday” to all return, “Weekend”. This would be done by having weekend at the bottom, and omitting the break starting with “Friday”. If we did this we would be able to return weekend for all 3 choices, since the choice would fall through, until it reached a break or the end of the switch statement. Thanks for watching More About PHP Switch Statements, Fall Through Explained, Exclude Break in PHP Switch Statements.