PHP/if
From DocForge
< PHP
if is a control flow statement which allows a PHP script to go down one of two execution paths based on an expression. If the expression evaluates to true, the first path is followed. If the expression evaluations to false, the first path is ignored and the else path is followed if it exists.
In PHP many types of expressions can be evaluated as boolean:
- An empty array evaluates to false; an array containing any elements evaluates to true.
- An empty string evaluates to false
- An assignment statement evaluates to the result of that assignment. So, for example, $var = some_function() evaluates to true if some_function returns true.
Syntax [edit]
if (<expression>) {
<statements>
}
if (<expression>) {
<statements>
}
else {
<statements>
}

