There are few conditional statements in PHP that is been used for putting different conditions. All the statements are as follows:
1. PHP if statement
It execute that code only if the situation is true otherwise not.
if statement Syntax:
if( condition ) {
if condition is true, then execute this code;
}
Example:
Result
PHP!
2. PHP if else statement
If true then execute the result, but in case condition false then output will be other coded thing.
PHP if else Syntax:
if (condition) {
if condition is true, then execute this code;
} else {
if condition is false, then execute this code;
}
Example:
Result:
PHP!
3. PHP if…else if….else statement
Sometime first condition get false then to check or test another condition we use this statement.
PHP if…else if….else Syntax:
if (condition) {
If condition is true, then execute this code;
} else if {
If condition is true, then execute this code;
} else {
If condition is false, then execute this code;
}
Example:
Result:
PHP!