The if statementif (expr) statement The if statement is one of the most important statements in PHP because it allows for conditional execution of code fragments. Here, expr is evaluated, and if it evaluates to TRUE, PHP will execute statement, whereas if expr evaluates to FALSE, PHP will ignore statement. Sometimes you will want to execute more than a single statement conditionally. In that case, you can group several statements into a compound statement. For example, this code displays a message if $value1 is bigger than $value2 and, if so, swaps the values: <?php if ($value1 > $value2) { echo "$value1 is bigger than $value2\n"; echo "Swapping the values."; $temp = $value1; $value1 = $value2; $value2 = $value1; } ?> |