Bird
0
0

Consider the following PHP code:

hard📝 Application Q9 of 15
PHP - Conditional Statements
Consider the following PHP code:
$marks = 85;
if ($marks > 90) {
echo 'Excellent';
} elseif ($marks > 80) {
echo 'Very Good';
} elseif ($marks > 70) {
echo 'Good';
} else {
echo 'Needs Improvement';
}

What will be the output?
AExcellent
BVery Good
CGood
DNeeds Improvement
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate conditions in order

    $marks = 85, check if > 90 (false), then > 80 (true).
  2. Step 2: First true condition executes

    Since $marks > 80 is true, 'Very Good' is printed and rest skipped.
  3. Final Answer:

    Very Good -> Option B
  4. Quick Check:

    Conditions checked top-down, first true runs [OK]
Quick Trick: First true condition in if-elseif chain executes [OK]
Common Mistakes:
  • Assuming multiple conditions print output
  • Misreading comparison operators
  • Ignoring order of elseif conditions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes