6 Control Structures

Control structures—conditionals and loops—are a staple of programming languages. PHP includes two general conditionals—if and switch—both of which you’ll master in this chapter. They allow you to establish a test and then perform actions based on the results. This functionality gives you the ability to make your Web sites even more dynamic. The discussion of if conditionals will introduce two last categories of operators: comparison and logical (you’ve already seen the arithmetic and assignment operators in the previous chapters). You’ll commonly use these in your conditionals along with the Boolean concepts of TRUE and FALSE.

Finally, this chapter begins programming with loops, which allow you to repeat an action ...

Get PHP for the Web: Visual QuickStart Guide, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.