PHP if…else…elseif Statements
in PHP if…else…elseif statements is called Conditional statements or decision-making code. you can create a test conditions to check weather condition is true or false and according to the result we can execute certain action.
Types of Condtional Statement
- if statement
- if…else statement
- if…elseif….else statement
- switch…case statement
1. if statement
This is the simplest conditional statements. The Block of Code ll run when the conditional statement ll be true.
if(condition){
// Code to be executed if condition ll be true.
}
2. if…else Statement
if(condition){
// Code to be executed if condition is true
} else{
// Code to be executed if condition is false
}
3. if…elseif…else Statement
if(condition){
// Code to be executed if condition is true
} elseif(condition){
// Code to be executed if condition is true
} else{
// Code to be executed if condition is false
}
4. Switch Statement
We ll discuss this in next Chapter.