Bird
0
0

What will be the output of this PHP code?

medium📝 Predict Output Q5 of 15
PHP - Operators
What will be the output of this PHP code?
$x = 8;
$y = 20;
echo $x <=> $y;
A1
B-1
C0
Dfalse
Step-by-Step Solution
Solution:
  1. Step 1: Understand spaceship operator output

    It returns -1 if left operand is less than right operand.
  2. Step 2: Compare values

    Since 8 is less than 20, output is -1.
  3. Final Answer:

    -1 -> Option B
  4. Quick Check:

    Left less than right returns -1 [OK]
Quick Trick: Less than returns -1 with <=> operator [OK]
Common Mistakes:
  • Confusing -1 with false
  • Expecting boolean output
  • Mixing up operator direction

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes