Using if-else statement in PHP

The PHP if-else statement executes specific blocks of code depending on whether a given condition is true or false. If the condition is true, the code block will be executed immediately following the condition, enclosed in curly braces {}. If the condition is false and there is an "else" statement after the "if", the block of code associated with the "else" condition will be executed. PHP also offers the "elseif" statement, which can be used between "if" and "else" to test multiple conditions sequentially. The associated code block is executed once a condition returns true, and the rest are skipped. It's important to remember that "if", "else", and "elseif" blocks are mutually exclusive, meaning only one block of code will be executed depending on which condition is met first. In this PHP if-else example, we execute a certain block of code based on the specified condition. Click Execute to run the PHP if-else example online and see the result.
Using if-else statement in PHP Execute
$score = 85;

if ($score >= 90) {
    echo "Grade: A";
} elseif ($score >= 80 && $score < 90) {
    echo "Grade: B";
} elseif ($score >= 70 && $score < 80) {
    echo "Grade: C";
} elseif ($score >= 60 && $score < 70) {
    echo "Grade: D";
} else {
    echo "Grade: F";
Updated: Viewed: 51 times