PHP爆炸-在每个数组项中运行循环

问题描述:

问题出在这里

我从数据库中检索以下数据字符串:

I retrieve the following data string from my database:

$row->exceptions = '1,2,3';

explode之后,我需要以下代码来检查每个爆炸件

After explode I need the below code to check each one of the exploded pieces

$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?

How can I make $exceptions[] loop through all keys from the exploded array so it evaluates if ==$i?

感谢您的帮助.

它足以替代:

if($exceptions[] == $i)

具有:

if(in_array($i,$exceptions))

顺便说一句,它消除了嵌套循环的需要.

By the way, it eliminates the need for a nested loop.