为什么这只打印出“-1”。文本的第一部分会发生什么。
echo "2 results of this " . "Apples" <=> "bananas";
由于
答案 0 :(得分:3)
.
的优先级高于<=>
,所以它的解析就好像你写的那样:
echo ("2 results of this " . "Apples") <=> "bananas";
相当于:
echo "2 results of this Apples" <=> "bananas";
所以它比较这两个字符串并只打印结果。
添加括号以获得所需内容:
echo "2 results of this " . ("Apples" <=> "bananas");
答案 1 :(得分:1)
因为它将首先连接字符串然后将应用太空船操作员比较
&#34;
2 results of this " . "Apples" <=> "bananas"; = -1
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^
string1 string2
尝试以下
$spaceship_result= "Apples" <=> "bananas";
echo "2 results of this ".$spaceship_result;
答案 2 :(得分:-1)
echo "2 results of this " . ("Apples" <=> "bananas");
这是一种方法