PHP If...Else

PHP If...Else...Elseif Statements

Conditional statements are used to perform different actions based on different conditions. They allow your PHP applications to make decisions!


The if Statement

The if statement executes some code if one condition is true.

Example

<?php
$t = 14;

if ($t < 20) { echo "Have a good day!"; } ?>

The if...else Statement

The if...else statement executes some code if a condition is true and another code if that condition is false.

The if...elseif...else Statement

The if...elseif...else statement executes different codes for more than two conditions.

Example

<?php
$t = 22;

if ($t < 10) { echo "Have a good morning!"; } elseif ($t < 20) { echo "Have a good day!"; } else { echo "Have a good night!"; } ?>