PHP If else
PHP if else Conditional Statement use in my website
In if else Conditional Statement used to check the conditional statement or test condition. we can perform a different action for different condition There are a various way to use if statement

- if
- if-else
- if-else-if
- nested if
If Statement:-
we have the following conditional statements: if statement executes some code if one condition is true
Finally Syntax like as:
|
1 2 3 |
if(condition){ //code to be executed } |
Flowchart:

Finally, Example –
|
1 2 3 4 5 6 |
<?php $num=22; if($num<100){ echo "$num is less than 100"; } ?> |
Finally Output:
|
1 |
22 is less than 100 |
If-else Statement:
PHP if-else Statement is executed different operations based on the different conditions whether condition True or False
If-else statement syntax-
|
1 2 3 4 5 |
if(condition){ //code to be executed if true }else{ //code to be executed if false } |
Flowchart-

Example:-
|
1 2 3 4 5 6 7 8 |
<?php $num=22; if($num%2==0){ echo "$num is even number"; }else{ echo "$num is odd number"; } ?> |
Output:-
|
1 |
22 is even number |
The if…elseif….else Statement
The if….elseif…else statement executes different codes for more than two conditions.
Seems Like Syntax-
|
1 2 3 4 5 6 7 |
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; } |
Another Example-
|
1 2 3 4 5 6 7 8 9 10 11 |
<?php $t = date("H"); if ($t < "10") { echo "Have a good morning!"; } elseif ($t < "20") { echo "Have a good day!"; } else { echo "Have a good night!"; } ?> |
Hence Output:-
|
1 2 |
"Have a good morning!" if the current time is less than 10, and "Have a good day!" if the current time is less than 20. Otherwise it will output "Have a good night!": |
Resource
PHP.net