Heim >Backend-Entwicklung >PHP-Tutorial >php 数据 foreach问题

php 数据 foreach问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-06 20:09:18997Durchsuche

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);

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

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn