为什么1 ... 2等价于PHP中的“ 10.2”?

Nat*_*ski 1 php symbols operators type-conversion

仅仅一秒钟之前,我正在使用PHP,试图弄清楚是否存在本机范围函数(最终找到range)。但是,我尝试的事情之一是:

echo 1...2;
Run Code Online (Sandbox Code Playgroud)

令我惊讶的是返回字符串"10.2"。谁能确切告诉我是什么语法引起的?对于splat操作员来说,这似乎不是一个有效的地方。

Jan*_*ann 5

The statement consists of three parts: 1., . and .2. The first one evaluates to the number 1, the second one is the string concatenation operator, and the latter one evaluates to 0.2. Thus, you get 10.2.

Equivalent example code:

$a = 1.;
$b = .2;
echo "a = $a\n";
echo "b = $b\n";
echo "a.b = ".($a.$b)."\n";
Run Code Online (Sandbox Code Playgroud)

outputs

a = 1
b = 0.2
a.b = 10.2
Run Code Online (Sandbox Code Playgroud)