The question is pretty much self-explanatory, I am having trouble how to end if statement in php.
For example,
<?php
if (argument) {
// end if statement
}
else if (different argument) {
// end if statement
}
else if (another different argument) {
// end if statement
}
else {
// do something
}
?>
Consider carefully how an if
condition works:
If (boolean condition) Then
(consequent)
Else
(alternative)
End If
When an interpreter finds an
If
, it expects a boolean condition ... and evaluates that condition. If the condition istrue
, the statements following thethen
are executed. Otherwise, the execution continues ... After either branch has been executed, control returns to the point after theend If
.
The if
statement will end if none of its conditions evaluate to true
or if one of its conditions evaluate to true
. The statement(s) associated with the first true
condition will evaluate, and the if
statement will end.
See Wikipedia's If–then(–else) for more.
Change :
<?php
if (argument) {
// end if statement
}
else if (different argument) {
// end if statement
}
else if (another different argument) {
// end if statement
else {
// do something
}
?>
To :
<?php
if (argument) {
// end if statement
}
else if (different argument) {
// end if statement
}
else if (another different argument) {
// end if statement
}
else {
// do something
}
?>
To use if statement, use the following syntax :
if (condition) {
// Put your codes here
}
Another example, if you use else if :
else if (condition) {
// Put your codes here
}
Use the curly bracket { } to contain your codes
PS: you just missed a } at the third if in your codes :)
There should not be a closing brace on line 4, but there should be one at the end of all conditional statements. The syntax is:
if (condition)
{
code to be executed if this condition is true;
} elseif (condition)
{
code to be executed if this condition is true;
} else
{
code to be executed if all conditions are false;
}
Further reference at: http://www.w3schools.com/php/php_if_else.asp