0
0
PHPprogramming~5 mins

Spaceship operator in PHP - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the spaceship operator in PHP?
The spaceship operator (<=>) is a comparison operator that returns -1, 0, or 1 when comparing two values. It returns -1 if the left value is less, 0 if they are equal, and 1 if the left value is greater.
Click to reveal answer
beginner
How does the spaceship operator differ from traditional comparison operators?
Unlike <, >, or == which return boolean true or false, the spaceship operator returns an integer -1, 0, or 1 to show the order between two values.
Click to reveal answer
beginner
What will 5 <=> 10 return in PHP?
It returns -1 because 5 is less than 10.
Click to reveal answer
beginner
What will 10 <=> 10 return in PHP?
It returns 0 because both values are equal.
Click to reveal answer
beginner
What will 15 <=> 10 return in PHP?
It returns 1 because 15 is greater than 10.
Click to reveal answer
What does the spaceship operator (<=>) return when the left value is less than the right value?
A0
Btrue
C1
D-1
What is the output of 7 <=> 7 in PHP?
A0
B1
C-1
Dfalse
Which of these is true about the spaceship operator?
AIt returns an integer indicating order.
BIt returns a boolean value.
CIt only works with strings.
DIt is used for assignment.
What will 20 <=> 10 return?
A-1
B0
C1
Dtrue
Which PHP version introduced the spaceship operator?
APHP 5.6
BPHP 7.0
CPHP 8.0
DPHP 7.4
Explain how the spaceship operator works and give an example comparing two numbers.
Think about how it shows if one number is less, equal, or greater than another.
You got /3 concepts.
    Describe a situation where using the spaceship operator is better than using multiple comparison operators.
    Consider when you want to know if one value is less, equal, or greater in a single comparison.
    You got /3 concepts.