在PHP 7中,引入了一项新功能 - Spaceship Operator.它用于比较两个表达式.当第一个表达式分别小于,等于或大于第二个表达式时,它返回-1,0或1.
示例
1);print("
"); print( 1 <=> 2);print("
"); print( 2 <=> 1);print("
"); print("
"); //float comparison print( 1.5 <=> 1.5);print("
"); print( 1.5 <=> 2.5);print("
"); print( 2.5 <=> 1.5);print("
"); print("
"); //string comparison print( "a" <=> "a");print("
"); print( "a" <=> "b");print("
"); print( "b" <=> "a");print("
");?>
它产生以下浏览器输出 :
0-110-110-11