Spaceship Operator

In PHP 7, a new feature, spaceship operator has been introduced. It is used to compare two expressions. It returns -1, 0 or 1 when first expression is respectively less than, equal to, or greater than second expression.

 <?php
print( 1 <=> 1);print("
");
    print( 1 <=> 2);print("
");
    print( 2 <=> 1);print("
");
?>
  

Leave a Reply

Your email address will not be published. Required fields are marked *