Chapter 2
PHP Flow Control
IN THIS CHAPTER
Adding conditional tests
Looping through code
Building functions
Understanding event-driven programming
In the previous chapter, you saw the basics of creating and running PHP programs. You saw how to use variables to hold data, but you didn'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. If you have code that you find yourself using frequently, I show how you can convert it 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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access