Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在试验 PHP 的弱/动态类型属性以准备测试,并且完全被这个字符串连接的输出所迷惑。有人可以解释这是怎么可能的吗?
<?php echo 1 . "/n" . '1' + 1 ?><br />
输出:
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;