Showing posts with label PHP else if ladder. Show all posts
Showing posts with label PHP else if ladder. Show all posts

Tuesday, April 2, 2024

PHP else if ladder

 PHP else if ladder

PHP else if ladder


PHP else if ladder :-


     PHP If ladder is a specific kind of nested if statement, where nesting only occurs in the else part. This statement is useful when an action needs to be chosen depending on a range of values.
      PHP, an “else if ladder” (also known as a “chain of if-else statements”) is a construct that allows you to evaluate multiple conditions in sequence. It’s particularly useful when you want to check different conditions one after the other and execute specific code blocks based on the first true condition encountered.


    Syntax :-

statement;

if (condition)

{
statement;
statement;

}
 else if (condition)
      statement;
     statement;
}
else
{
statement;
statement;
}


PHP else if ladder

Example :-
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="css/bootstrap.css">

</head>
<body class="bg-primary">
    <div class="bg-white col-md-4 mx-auto mt-5 p-4">
<h2>Positive Negative or zero number check </h2>
<form action="else-if-ladder-p-n.php" method="get">
   
    <input type="number" name="no" class="form-control" required>
</form>

<?php
$score = 85;

if ($score >= 90) {
    echo "Grade: A";
} elseif ($score >= 80) {
    echo "Grade: B";
} elseif ($score >= 70) {
    echo "Grade: C";
} elseif ($score >= 60) {
    echo "Grade: D";
} else {
    echo "Grade: F";
}
?>

</div>
</body>
</html>


PHP else if ladder :-
Output :-


else if ladder output



PHP While loop