Bird
0
0

What will this PHP code output?

medium📝 Predict Output Q4 of 15
PHP - Conditional Statements
What will this PHP code output?
$age = 20;
if ($age >= 18) {
echo 'Adult';
} else {
echo 'Minor';
}
AMinor
BAdult
CError
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Check the condition in the if statement

    The condition is $age >= 18. Since $age is 20, this is true.
  2. Step 2: Determine which block runs

    Because the condition is true, the code inside the if block runs, printing 'Adult'.
  3. Final Answer:

    Adult -> Option B
  4. Quick Check:

    Condition true = if block runs [OK]
Quick Trick: True condition runs if block, else runs else block [OK]
Common Mistakes:
  • Confusing which block runs on true condition
  • Expecting 'Minor' when age is 20
  • Thinking code causes error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes