|
| HOW TO USE if STATEMENTS IN PHP
If statements execute a certain specified block of code only if a certain specified condition is true. The general format is as follows:
if (certain condition is true)
{
specified block of code to execute
}
Example:
$lastName="Bond";
if ($lastName=='Bond')
{
echo "Are you related to James?";
}
Only if the specified condition of $lastName=='Bond' is true, will the block of code {between the curly braces} execute which, in this example, is to echo Are you related to James?
In the above case, $lastName is Bond (as we declared it at this line: $lastName="Bond";) so therefore the block of code {between the curly braces} will execute.
If $lastName was not Bond, the block of code {between the curly braces} won't execute and nothing is outputted as below.
Example:
$lastName="Smith";
if ($lastName=='Bond')
{
echo "Are you related to James?";
}
Nothing is outputted.
|
|