WEB DEVELOPER SITE
PYTHON
 

PHP 7 - Spaceship Operator


Return 0,-1,1 when first expression is respectively less than, equal to, or greater than second expression.

PHP Data Types

Example

<?php
   //integer comparison
   print( 1 <=> 1);print("
"); print( 1 <=> 5);print("
"); print( 2 <=> 1);print("
"); print("
"); //float comparison print( 3.5<=> 3.5);print("
"); print( 3.5 <=> 4.5);print("
"); print( 3.5 <=> 2.5);print("
"); print("
"); //string comparison print( "x" <=> "x");print("
"); print( "x" <=> "y");print("
"); print( "y" <=> "x");print("
"); ?>

Try it yourself » Result
0
-1
1

0
-1
1

0
-1
1