PHP - The if...elseif....else Statement

Use the if....elseif...else statement to specify a new condition to test, if the first condition is false.
Syntax
if (condition) {
    code to be executed if condition is true;
}
elseif (condition) {
    code to be executed if condition is true;
}
else {
    code to be executed if condition is false;
}
The example below will output "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!":
Example
<?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!";
}
?>
Next Example calculate  Grade of Student's Marks:
<!DOCTYPE html>
<html>
<head>

<title></title>
</head>
<body>


<h2> else if or Ledder if else</h2>
<pre>$marks=35;
if($marks>70){
echo " You are pass with grade A";
}else if($marks>50){
echo " You are pass with grade B";
}
else if($marks>40){
echo " You are pass with grade C";
}
else{
echo " You are pass with grade D";
}
</body>
</html>

No comments:

| Designed by Harhiktech