編程學習網 > 編程教程 > PHP7 教程
2016
09-20

PHP7飛船操作符

清華大佬耗費三個月吐血整理的幾百G的資源,免費分享!....>>>

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

示例

<?php
   //integer comparison
   print( 1 <=> 1);print("<br/>");
   print( 1 <=> 2);print("<br/>");
   print( 2 <=> 1);print("<br/>");
   print("<br/>");
   //float comparison
   print( 1.5 <=> 1.5);print("<br/>");
   print( 1.5 <=> 2.5);print("<br/>");
   print( 2.5 <=> 1.5);print("<br/>");
   print("<br/>");
   //string comparison
   print( "a" <=> "a");print("<br/>");
   print( "a" <=> "b");print("<br/>");
   print( "b" <=> "a");print("<br/>");
?>
這將在瀏覽器產生輸出以下結果-
0
-1
1

0
-1
1

0
-1
1

掃碼二維碼 獲取免費視頻學習資料

編程學習