Spaceship Operator

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

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

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

<?php

$a = 1;
$b = 3;

print $a <=> $b;

?>

Documentation

See also Weird operators in PHP, What Is the PHP Spaceship Operator?

Related : Comparison

Added in PHP 7.0