Home >Backend Development >PHP Tutorial >php 数据 foreach问题

php 数据 foreach问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-06 20:09:181004browse

1、数据结构如下

<code><?php $arr = array(0=>(store,img_parth,cat_list=>array(1=>array(),2=>array()),1=>(store,img_parth,cat_list=>array(1=>array(),2=>array())));</code>

这种数据结构 请教一下啊 该如何用foreach遍历呢? 遍历完成后以数组形式保存

希望得到的结果如下 $arr['b_id']['cat_list']['1'];$arr['b_id']['cat_list']['2'] ...

回复内容:

1、数据结构如下

<code><?php $arr = array(0=>(store,img_parth,cat_list=>array(1=>array(),2=>array()),1=>(store,img_parth,cat_list=>array(1=>array(),2=>array())));</code>

这种数据结构 请教一下啊 该如何用foreach遍历呢? 遍历完成后以数组形式保存

希望得到的结果如下 $arr['b_id']['cat_list']['1'];$arr['b_id']['cat_list']['2'] ...

$arr = array('b_id','store','img_parth','cat_list'=>array(1=>array(),2=>array()));

foreach($arr as $k => $v)
{

<code>if(!is_array($v))
{
    $data[] = $v;
}
else
{
    foreach($v as $c_k => $c_v)
    {
        foreach($data as $v1)
        {
            $result[$v1][$c_k] = $c_v;
        }
    }
}</code>

}

var_dump($result);

顺序问题没把握,写个简单的。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn