PHP Conditional Statements
PHP Conditional Statements
Conditional Statements are used to perform actions based on different conditions. Sometimes when we write a program, we want to perform some different actions for different actions. We can solve this by using conditional statements.
In PHP we have these conditional statements:
- if Statement.
- if-else Statement
- If-elseif-else Statement
- Switch statement
1. if Statement
This statement executes the block of code inside the if statement if the expression is evaluated as True.
Example:
2. if-else Statement
This statement executes the block of code inside the if statement if the expression is evaluated as True and executes the block of code inside the else statement if the expression is evaluated as False.
Example:
3. If-else-if-else
This statement executes different expressions for more than two conditions.
Example:
4. Switch Statement
This statement allows us to execute different blocks of code based on different conditions. Rather than using if-elseif-if, we can use the switch statement to make our program.
Example: