【发布时间】:2015-06-18 18:19:18
【问题描述】:
-
这是代码:
<?php $a = "4 fox and 3 cows"; // it is simple string $b = 22; echo $ab = $a + $b; echo "output::".$ab; ?>'输出: 只读取第一个索引 26 这背后的逻辑是什么..? 相反,我应该得到一个错误..
2.另一个例子:
<?php
$a = "four fox and 3 cows"; // it is simple string
$b = 22;
echo $ab = $a + $b;
echo "output::".$ab;
?>'
output:
22
what is the logic behind this..?
【问题讨论】:
-
我们需要一些代码来提供帮助
-
$a通过截断不属于有效 int 的所有内容转换为 int。 4+22 = 26。 -
为什么会出现错误?当您对字符串执行加法时,PHP 会首先尝试将字符串转换为整数。在这种情况下,它会在字符串的开头看到
4,并丢弃其余部分。 (如果字符串开头没有有效数字,则变为 0)。所以 22 + 4 是 26。 -
字符串浓度与
.pperatot -
我喜欢这类问题总是得到 4 个以上的答案...
标签: php