PHP爆炸-在每个数组项中运行循环 [英] PHP explode - running loop through each array item

查看:91
本文介绍了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.

这篇关于PHP爆炸-在每个数组项中运行循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆