Hi,
PHP Control Structures Statement
if (expr)
statement
elseif (expr)
statement
elseif (expr)
statement
...
else
statement
if Statements are the most common conditional constructs, and they exist in most programming languages. The expression in the if statement is referred to as the truth expression. If the truth expression evaluates to
true, the statement or statement list following it are executed; otherwise,
they’re not. You can add an else branch to an if statement to execute code only if all the truth expressions in the if statement evaluated to false:
PHP Code:
if ($var >= 50)
{
print '$var is in range';
} else
{
print '$var is invalid';
}
Notice the braces that delimit the statements following if and else,
which make these statements a statement block. In this particular case, you
can omit the braces because both blocks contain only one statement in them.
It is good practice to write these braces even if they’re not syntactically
required. Doing so improves readability, and it’s easier to add more statements
to the if block later (for example, during debugging).
The elseif construct can be used to conduct a series of conditional checks
and only execute the code following the first condition that is met.