我正在尝试PHP的弱/动态类型属性以准备测试,并且完全被这个字符串连接的输出所困惑。有人可以解释一下这是怎么回事吗?
<?php echo 1 . "/n" . '1' + 1 ?><br />
输出:
2
答案 0 :(得分:2)
分析:
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;