Conditional statement are used to perform different
actions based on different conditions.
If statement execute code and return True.
If-else statement execute code and return true or false.
else-if statement execute different codes for more
than two conditions.
Example of If:
<?php
$day = "monday";
If($day == "Monday")
{
echo "Have a good day!";
}
?>
Example of if-else:
<?php
$age = 30;
If($age >= 18)
{
echo "you are young";
}
else {
echo "you are child";
}
?>
Example of if elseif:
<?php
$per = 55;
If($per>=80)
{
echo "A+ Grade";
}
else if($per >=70)
{
echo "A grade";
}
else {
echo "You are Fail";
}
?>
PHP SWITCH-case STATEMENT
Switch statement same as if statement but, there is
a difference is that switch statement is only use when
You want to compare the same variable (or expression)
with many different values and execute a different pieces
of code depending on which value it equals too.
This is exactly the SWITCH statement.
Switch Example:
$month = 1;
switch($month)
{
case 1:
echo "January";
break;
case 2:
echo "Feburary";
break;
case 3:
echo "March";
break;
.
.
.
default:
echo "Please type number between 1 to 12 ";
break;
}