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?✗ Incorrect
The spaceship operator returns -1 when the left value is less than the right value.
What is the output of
7 <=> 7 in PHP?✗ Incorrect
It returns 0 because both values are equal.
Which of these is true about the spaceship operator?
✗ Incorrect
The spaceship operator returns -1, 0, or 1 to indicate order between two values.
What will
20 <=> 10 return?✗ Incorrect
It returns 1 because 20 is greater than 10.
Which PHP version introduced the spaceship operator?
✗ Incorrect
The spaceship operator was introduced in PHP 7.0.
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.