Conditionals
Conditionals alter program flow. They enable you to ask questions about certain things and respond to the answers you get in different ways. Conditionals are central to dynamic web pages—the goal of using PHP in the first place—because they make it easy to create different output each time a page is viewed.
There are three types of nonlooping conditionals: the if statement, the switch statement, and the ? operator. By nonlooping, I mean that the
actions initiated by the statement take place and program flow then
moves on, whereas looping conditionals (which we’ll come to shortly)
execute code over and over until a condition has been met.
The if Statement
One way of thinking about program flow is to imagine it as a single-lane highway that you are driving along. It’s pretty much a straight line, but now and then you encounter various signs telling you where to go.
In the case of an if
statement, you could imagine coming across a detour sign that you have
to follow if a certain condition is TRUE. If so, you drive off and follow the
detour until you return to where it started and then continue on your
way in your original direction. Or, if the condition isn’t TRUE, you ignore the detour and carry on
driving (see Figure 4-1).

The contents of the if condition can be any valid PHP expression, including equality, comparison, tests ...