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

php 数据 foreach问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:09:18
Original
1010 people have browsed it

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>
Copy after login
Copy after login

这种数据结构 请教一下啊 该如何用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>
Copy after login
Copy after login

这种数据结构 请教一下啊 该如何用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>
Copy after login

}

var_dump($result);

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

Related labels:
php
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template