PHP 中的点运算符

发布于 2024-11-19 23:08:47 字数 314 浏览 0 评论 0原文

我以为我已经知道 字符串运算符 很好,直到今天我被问到了一个问题。这个问题看起来很简单:

echo 100...100;

乍一看我以为它会出现语法错误。但当我运行代码并看到结果时,我完全困惑了。结果是

1000.1

所以我想知道怎么会发生这种情况?

谢谢。

I thought I've known the String Operator . well enough until I was asked a question about it today. The question looks quite simple:

echo 100...100;

At the first glance I thought it would make a syntax error. But when I ran the code and saw the result I was totally confused. The result is

1000.1

So I wonder how could this happen?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

雪化雨蝶 2024-11-26 23:08:47

像这样阅读:

(100.) . (.100)

因此它连接了 1000.1

Read it like this:

(100.) . (.100)

Thus it concats 100 and 0.1.

清秋悲枫 2024-11-26 23:08:47

假设您的

echo 100...100;

意思是 PHP 的优点。 :)
该语句被理解为

100. . .100

相当于

100.0 . 0.1

<=>

'100' . '0.1'

<=>

'1000.1'

Assuming you meant

echo 100...100;

The reason for this is the beauty of PHP. :)
This statement is understood as

100. . .100

which is equivalent to

100.0 . 0.1

<=>

'100' . '0.1'

<=>

'1000.1'
暖阳 2024-11-26 23:08:47

您可以将其读作 echo 100 。 0.1 。

You can read it as echo 100 . 0.1.

以为你会在 2024-11-26 23:08:47

实际上,只有在没有引号的情况下才有效:

echo "100...100";   100...100  << with quotes the . is just a char

echo 100 . 100;     100100     << two concatenated strings "100"

echo 100.100;       100.1      << 100.100 is just a number

echo 100...100;     1000.1     << what you asked

echo 100. . .100;   1000.1     << what PHP actually interprets

Actually, that only works without the quotes:

echo "100...100";   100...100  << with quotes the . is just a char

echo 100 . 100;     100100     << two concatenated strings "100"

echo 100.100;       100.1      << 100.100 is just a number

echo 100...100;     1000.1     << what you asked

echo 100. . .100;   1000.1     << what PHP actually interprets
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文