【发布时间】:2021-07-24 22:27:11
【问题描述】:
我有这样的代码:
<?php
$kecuali = "6,8,9";
for ($x = 0; $x < 15; $x++) {
if ($x == $kecuali) {
continue;
}
echo "The number is: $x <br>";
}
?>
这样的结果
The number is: 0
The number is: 1
The number is: 2
The number is: 3
The number is: 4
The number is: 5
The number is: 7
The number is: 8
The number is: 9
The number is: 10
The number is: 11
The number is: 12
The number is: 13
The number is: 14
为什么数字 8 和 9 仍然在结果中,而不是数字 6?我该如何解决这个问题,以便所有 3 个数字都不会出现在结果中?
【问题讨论】:
-
$kecuali是一个字符串伙伴。而是检查为in_array($x,explode(",",$kecuali))。您还可以缓存爆炸部分。 -
哇,谢谢兄弟,你解决了我的问题。
标签: php arrays string for-loop