3

我正在试验 PHP 的弱/动态类型属性以准备测试,并且完全被这个字符串连接的输出所迷惑。有人可以解释这是怎么可能的吗?

<?php echo  1 . "/n" . '1' + 1 ?><br />

输出:

2

4

1 回答 1

1

分析:

echo  1 . "/n" . '1' + 1;

相当于

//joined first 3 items as string
echo "1/n1"+1;

相当于

//php faces '+' operator, it parses '1/n1' as number
//it stops parsing at '/n' because a number doesn't
//contain this character
echo "1"+1;

相当于

echo 1+1;
于 2014-08-25T03:00:10.043 回答