当我用foreach运行变量数组时,我发现在使用加法时没有显示回波字符串,只使用operator.But回波赋值操作符,display.What是不能用加法运算符回显字符串的原因吗?
<?php
$key = 3;
echo $key+1;echo "<br>"; // 4
echo "The answer is ".++$key; // The answer is 4
echo "The answer is ".$key+1; // 1
//last echo is why can't display string and not getting 4
?>发布于 2016-03-11 08:35:04
那是因为你在用字符串做数学运算。
"The answer is ".$key+1与
"The answer is 3" + 1 which equals 1;您需要使用()来清除范围
$key = 3;
"The answer is ".($key+1) === "The answer is 4"也是
echo "The answer is ".++$key; // The answer is 4
echo "The answer is ".($key+1); // This would be 5, beause you're incrementing $key by 1 beforehandhttps://stackoverflow.com/questions/35935466
复制相似问题