我有这样的代码:
for($nrt=0; $nrt<$actualline; $nrt++) {
echo $sidesIndexes[$nrt]." - ".$nrt."<br/>";
if($sidesIndexes[$nrt]==$nrt) {
echo "am I in??? ".$sidesIndexes[$nrt]." is different than ".$nrt."<br/>";
}
}该打印:
# - 0
am I in??? # is different than 0
# - 1
# - 2
# - 3
# - 4
# - 5
# - 6
# - 7
# - 8
# - 9
# - 10
# - 11
# - 12
# - 13
# - 14
# - 15
# - 16
# - 17
# - 18
# - 19我累了吗?如何才能获得am I in??? # is different than 0消息?
发布于 2011-04-18 23:27:17
在进行比较时,提供的the string is converted to a numeric value。
那么是的,0 == 0。
您应该使用===与检查变量类型进行比较:
if($sidesIndexes[$nrt] === $nrt) {只有当两个变量都是相同类型(如整数、字符串等)时,才会出现这种情况。
发布于 2011-04-18 23:22:21
在php '#‘中,== 0解析为true
了解更多信息:http://php.net/manual/en/language.operators.comparison.php和http://www.php.net/manual/en/types.comparisons.php
发布于 2011-04-18 23:23:35
我假设这是PHP,因为它看起来很像。在PHP中,Zero的计算结果是很多东西。在这种情况下,它看起来像0 == null。若要在同时检查类型的情况下进行强相等比较,请使用===。
0 == null // true
0 == false // true
0 == 0 // true
0 === null // false
0 === false // false
0 === 0 // truehttps://stackoverflow.com/questions/5705114
复制相似问题