PHP Conditional Statements
Conditional Statements are those statements which will be executed only when the condition is satisfied.
1.If Statement
The IF statement is executed if the condition is true.
Syntax : if( condition) { //your code here }
Example:
2.If Else Statement
In the IF Else statement, the "IF" part is executed if the condition is true else the "Else" part will be executed.
Syntax :
if( condition)
{
//your code here
}
else
{
//your code here
}
Example :
3.If Elseif Else Statement
In the "IF Elseif Else" statement, first the compiler check if the "IF" condition is true.If it is true, the respective code will be executed. But when the "IF" condition is false, the compiler will check if the "elseif" condition is true. If is true, the respective code will be executed. If both the "IF" and "Elseif" conditions are not satisfied, then the "Else" part will be executed.
Syntax :
if( condition)
{
//will be executed when the above if condition is true.
}
elseif( condition )
{
//will be executed when the if condition is false and the elseif condition is true.
}
else
{
//will be executed when none of the above conditions are satisfied.
}
Example :
© Copyright - 2018 - 2023 | All rights reserved at Funda of Web IT