Chapter 2

PHP Flow Control

IN THIS CHAPTER

check Adding conditional tests

check Looping through code

check Building functions

check 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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.