以下运行循环的问题:PHP爆炸 - 通过每个数组项
我检索我的数据库中的以下数据串:
$row->exceptions = '1,2,3';
explode
后,我需要下面的代码来检查的每一个爆炸碎片
$exceptions = explode(",", $row->exceptions);
//result is
//[0] => 1
//[1] => 2
//[2] => 3
for ($i = 0; $i <= $row->frequency; $i++) {
if ($exceptions[] == $i) {
continue;
} else {
//do something else
}
}
我怎样才能通过所有键$exceptions[]
循环从爆炸阵列,因此评估是否==$i
?
感谢您的帮助。
[查找数组中的值]的可能重复(http://stackoverflow.com/questions/4703004/find-value-in-array) – 2011-05-08 05:34:44
不确定 - 在这里我需要一个解决方案而不是找到一个特定的键,但要循环所有键 – pepe 2011-05-08 05:37:00
我不知道我有你的问题,所以我发表评论:如果我得到它,它应该足以代替“if($ exceptions [] == $ i )“with”if(in_array($ i,$ exceptions))“。 – 2011-05-08 05:50:13