我有这个代码:
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
消息? 最佳答案
比较时,the "#" string is converted to a numeric value给出0。
然后是0 == 0。
您应该使用===与检查变量类型进行比较:
if($sidesIndexes[$nrt] === $nrt) {
仅当两个变量都属于同一类型(例如整数,字符串等)时,才为true。