PHP 太空船运算符(组合比较符)
PHP 7 新增加的太空船运算符(组合比较符)用于比较两个表达式 $a 和 $b,如果 $a 小于、等于或大于 $b时,它分别返回-1、0或1。
实例
<?php // 整型比较 print( 1 <=> 1);print(PHP_EOL); print( 1 <=> 2);print(PHP_EOL); print( 2 <=> 1);print(PHP_EOL); print(PHP_EOL); // PHP_EOL 为换行符 // 浮点型比较 print( 1.5 <=> 1.5);print(PHP_EOL); print( 1.5 <=> 2.5);print(PHP_EOL); print( 2.5 <=> 1.5);print(PHP_EOL); print(PHP_EOL); // 字符串比较 print( "a" <=> "a");print(PHP_EOL); print( "a" <=> "b");print(PHP_EOL); print( "b" <=> "a");print(PHP_EOL); ?>
以上程序执行输出结果为:
0 -1 1 0 -1 1 0 -1 1
相关推荐
Noneyes 2020-11-10
zyyjay 2020-11-09
xuebingnan 2020-11-05
samtrue 2020-11-22
stefan0 2020-11-22
yifangs 2020-10-13
songshijiazuaa 2020-09-24
hebiwtc 2020-09-18
天步 2020-09-17
83911535 2020-11-13
whatsyourname 2020-11-13
zhouyuqi 2020-11-10
mathchao 2020-10-28
王志龙 2020-10-28
wwwsurfphpseocom 2020-10-28
diskingchuan 2020-10-23
savorTheFlavor 2020-10-23