Bird
0
0

What is the output of this PHP code?

medium📝 Predict Output Q13 of 15
PHP - Conditional Statements
What is the output of this PHP code?
$age = 20;
$result = ($age >= 18) ? 'Adult' : 'Minor';
echo $result;
AAdult
BError
C20
DMinor
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate the condition

    $age is 20, so ($age >= 18) is true.
  2. Step 2: Apply ternary operator

    Since condition is true, $result is set to 'Adult'.
  3. Final Answer:

    Adult -> Option A
  4. Quick Check:

    20 >= 18 ? 'Adult' : 'Minor' = 'Adult' [OK]
Quick Trick: Check condition result true or false to pick output [OK]
Common Mistakes:
  • Assuming output is the number 20
  • Confusing true and false branches
  • Expecting syntax error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes