|
Chapter 7
Controlling the Flow of the Script
In This Chapter
Changing the order in which statements are executed
Setting up conditions
Joining simple conditions to make complex conditions
Using conditions in conditional statements and loops
Writing
if
statements
Building and using loops for repeated statements
Breaking out of loops
P
HP scripts are a series of instructions in a file. PHP begins at the top
of the file and executes each instruction, in order, as it comes to it.
However, some scripts need to be more complicated. You may want your
script to display one page to new customers and a different page to existing
customers. Or you may need to display a list of phone numbers by executing
a single
echo
statement repeatedly, once for each phone number. This chap-
ter describes how to change the order in which simple statements are exe-
cuted by using complex statements such as conditional statements or loops.
Changing the Order of
Statement Execution
Simple statements in PHP are executed one after another from the beginning
of the script to the end. For example, the following statements in a script are
executed in order:
$a = “Good Morning”;
echo $a;
$a = “Good Afternoon”;
echo $a;
To change the order of execution of these statements, you have to change the
order of the statements themselves, as follows:
|