|
| HOW TO USE if else STATEMENTS IN PHP
If else statements execute a certain specified block of code if a certain specified condition is true and a different block of code if that certain specified condition is false. The general format is as follows:
if (certain condition is true)
{
specified block of code to execute
}
else
{
different block of code to execute
}
Example:
if($lastName=='Bond')
{
echo "Are you related to James?";
}
else
{
echo "Go away!";
}
Only if the specified condition of $lastName=='Bond' is true, will the first block of code {between the curly braces} execute and in our case will echo: Are you related to James?
If $lastName is anything other than Bond, the second block of code after the else and {between the curly braces} will execute and in our case will echo: Go away!
|
|