PHP7飛船操作符

在PHP7,一個新的功能,飛船操作符已經被引入。它是用於比較兩個表達式。當第一個表達式比第二個表達式分別小於,等於或大於它返回-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
-1
1

0
-1
1

0
-1
1