|
| HOW TO USE elseif STATEMENTS IN PHP
Elseif statements are used in if else statements to add additional conditions. You must start with an if statement and Elseif statements must come after that. The general format is as follows:
if(certain condition is true)
{
specified block of code to execute
}
elseif(another 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?";
}
elseif($lastName=='Lee')
{
echo "Are you related to Bruce?";
}
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=='Lee' is true at the elseif statement, will the second block of code {between the curly braces} execute and in our case will echo: Are you related to Bruce?
If $lastName is anything other than Bond or Lee, the third block of code {between the curly braces} will execute and in our case will echo: Go away!
 |
|
|