[英]A string in PHP that doesn't make sense
I was experimenting with weak/dynamic typing properties of PHP in preparation for a test and was completely baffled by the output of this string concatenation. 我正在试验PHP的弱/动态类型属性以准备测试,并且完全被这个字符串连接的输出所困惑。 Can someone explain how this is even possible?
有人可以解释这是怎么可能的吗?
<?php echo 1 . "/n" . '1' + 1 ?><br />
output: 输出:
2
2
Analysis: 分析:
echo 1 . "/n" . '1' + 1;
is equivalent to 相当于
//joined first 3 items as string
echo "1/n1"+1;
is equivalent to 相当于
//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;
is equivalent to 相当于
echo 1+1;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.