Bird
0
0

What will be the output of this PHP code?

medium📝 Predict Output Q13 of 15
PHP - Operators
What will be the output of this PHP code?
$a = 5;
$b = 10;
$result = $a > $b ? 'Yes' : 'No';
echo $result;
A5
BYes
CNo
D10
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate the comparison $a > $b

    Since 5 is not greater than 10, the condition is false.
  2. Step 2: Apply the ternary operator

    Because the condition is false, the expression returns 'No'.
  3. Final Answer:

    No -> Option C
  4. Quick Check:

    5 > 10 is false, so output is 'No' [OK]
Quick Trick: Ternary returns first if true, else second [OK]
Common Mistakes:
  • Assuming 5 > 10 is true
  • Confusing ternary syntax
  • Expecting numeric output instead of string

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes