- if statement
- if … else statement
- if … elseif ….. else statement
- Nested if statement
- switch statement
PHP IF Statement
If the condition / statement is true then it will allow to execute some code.
<?php $data = 10; if($data > 6){ // do something if the condition is true } ?>
PHP IF … Else Statement
If the condition is not true else statement will be execute the code.
<?php $data = 10; if($data > 6){ // do something if the condition is true }else{ // do something if the condition is false } ?>
PHP IF … Elseif … Else Statement
If the condition is not true, then we can check with another condition check using multiple Elseif, and any of the statements are not true then, else statement will be execute the code.
<?php $data = 10; if($data > 6){ // do something if the condition is true }else if(){ // do something if the condition is true } . . . else{ // do something if the condition is false. } ?>