为什么 echo 不打印文本的第一部分

Why echo does not print the first part of the text

为什么只打印出“-1”。文本的第一部分发生了什么。

echo "2 results of this " .    "Apples" <=> "bananas";

谢谢

.<=> 具有更高的优先级,所以它被解析为就好像你写了:

echo ("2 results of this " . "Apples") <=> "bananas";

相当于:

echo "2 results of this Apples" <=> "bananas";

所以它比较这两个字符串并只打印结果。

加括号得到你想要的:

echo "2 results of this " . ("Apples" <=> "bananas");

因为它会首先连接字符串,然后应用飞船运算符比较

"

2 results of this " .    "Apples" <=> "bananas"; = -1
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^      ^^^^^^^^^
string1                               string2

试试下面

  $spaceship_result=  "Apples" <=> "bananas";
  echo "2 results of this ".$spaceship_result;