Chaining Spaceship

../_images/chaining_spaceship.png

It is possible to chain several spaceship operations by using the coalesce operator ?:. When the first spaceship operator returns 1 or -1, its value is immediately used. On the other hand, when the operation leads to 0, the coalesce ?: uses the else branch, where the second spaceship operator is used, to the same effect.

This expression here replaces a call to array_multi_sort().

And of course, literally chaining spaceships together is a very bad idea.

See Also

PHP Features