Chapter 2
PHP Flow Control
IN THIS CHAPTER
Adding conditional tests
Looping through code
Building functions
Working with event-driven programming
In the preceding chapter, I cover the basics of creating and running PHP programs. I show you how to use variables to hold data, but you don’t really do much with them to test the data and perform operations. In this chapter, I walk through how to use the PHP conditional tests to control how your program behaves, as well as show how to loop through code to perform multiple iterations. In case you have code that you find yourself using frequently, I show how you can convert them into functions to share among your programs. Finally, I cover how to use PHP code in your event-driven web applications to add to your dynamic web applications.
Using Logic Control
Only having variables and echo
statements in your PHP program would be pretty boring. You need to give your programs some intelligence so that they can make decisions based on what's happening in the application and display different sets of content based on those decisions.
Every programming ...
Get PHP, MySQL, & JavaScript All-in-One For Dummies 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.