Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Spaceship Operator

Spaceship operator is an operator which reports if a value is larger, equal or smaller than another value. It returns 1, 0 or -1 in each case, respectively.

The spaceship operator may be replaced by a - minus sign, if the compared values are correct. It may also be replaced with !=, since -1 and 1 are both cast to true.

The spaceship operator got its name from its resemblance to a flying saucer. Battleship operator, or death star operator do not exist.

<?php

    $a = 1;
    $b = 3;
    
    print $a <=> $b;

?>

Documentation

See Also