if
if
The construct is one of the most important features of many languages, PHP included. It allows for conditional execution of code fragments. PHP features an structure that is similar to that of C:
`if``if````php if (expr) statement
As described in , is evaluated to its
Boolean value. If evaluates to true,
PHP will execute , and if it evaluates
to false - it'll ignore it. More information about what values evaluate
to false can be found in the
section.
the section about
expressions'Converting to boolean'
The following example would display if is bigger
than :
`$a``$b````php
<?php
if ($a > $b)
echo "a is bigger than b";
?>
Often you'd want to have more than one statement to be executed conditionally. Of course, there's no need to wrap each statement with an clause. Instead, you can group several statements into a statement group. For example, this code would display if is bigger than , and would then assign the value of into :
`if$a$b$a$b````php
statements can be nested infinitely within other
statements, which provides you with complete
flexibility for conditional execution of the various parts of your
program.
`If``if`