The if Statement

Figure 3-1 lays out the form of an if statement.

Figure 3-1. The form of an if statement.

The if statement executes a statement if the expression inside the parentheses evaluates to true; otherwise the code is skipped. It may be a single statement followed by a semicolon. Usually it's a compound statement surrounded by curly braces. An else statement may appear immediately after the statement and has a statement of its own. It, too, may be either single or compound. It is executed only when the previous expression is false. In between an if statement and an else statement you may put as many elseif statements as you'd like. ...

Get Core PHP Programming: Using PHP to Build Dynamic Web Sites 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.