Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP PHP Arrays and Control Structures PHP Conditionals Comparison Operators

Sean Flanagan
Sean Flanagan
33,235 Points

Spaceship operator

Hi.

I'm not sure I get this. It says that spaceship means an integer which is less than, equal to or greater than 0 when the first value is respectively less than, equal to or greater than the second value. Does this mean the second value has to be zero? Could someone please explain spaceship to me in detail?

Cheers!

1 Answer

The spaceship returns a integer based on the difference between $a and $b

<?php

//$a <=> $b 
if $a == $b
// 0

if $a < $b
// -1

if $a > $b
// 1

?>
Sean Flanagan
Sean Flanagan
33,235 Points

Perfect! I've upvoted and given you Best Answer for this.

Thank you Rich! :-)