Bird
0
0

Which of the following is the correct syntax to compare two variables $a and $b using the spaceship operator in PHP?

easy📝 Syntax Q12 of 15
PHP - Operators
Which of the following is the correct syntax to compare two variables $a and $b using the spaceship operator in PHP?
A$a <=> $b;
B$a => $b;
C$a <==> $b;
D$a <-> $b;
Step-by-Step Solution
Solution:
  1. Step 1: Recall the spaceship operator syntax

    The spaceship operator is written as <=> between two values.
  2. Step 2: Check each option

    $a <=> $b; uses <=> correctly. Others have invalid or incorrect symbols.
  3. Final Answer:

    $a <=> $b; -> Option A
  4. Quick Check:

    Correct operator is <=> [OK]
Quick Trick: Spaceship operator is exactly <=> with no extra symbols [OK]
Common Mistakes:
  • Using => which is for arrays
  • Adding extra equals signs
  • Using arrows like <-> which is invalid

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes