1. The data structure is as follows: {code...}. How can I use foreach to traverse the data structure? After the traversal is complete, save the expected result as an array: $ arr [& #039; B _id & #039;] [& #039; cat_list & #039;] [& #039; 1 & #039;]; $ arr [& #039; B _id & #039;] [& #039; cat_list & #039;] [& #039; 2 & #039;]... 1. The data structure is as follows:
(store,img_parth,cat_list=>array(1=>array(),2=>array()),1=>(store,img_parth,cat_list=>array(1=>array(),2=>array())));
How can I use foreach to traverse the data structure? Save as an array after traversing
The expected result is as follows:$arr['b_id']['cat_list']['1'];$arr['b_id']['cat_list']['2'] ...
Reply content:
1. The data structure is as follows:
(store,img_parth,cat_list=>array(1=>array(),2=>array()),1=>(store,img_parth,cat_list=>array(1=>array(),2=>array())));
How can I use foreach to traverse the data structure? Save as an array after traversing
The expected result is as follows:$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)
{
if(!is_array($v)){ $data[] = $v;}else{ foreach($v as $c_k => $c_v) { foreach($data as $v1) { $result[$v1][$c_k] = $c_v; } }}
}
Var_dump ($ result );
I'm not sure about the order. It's easy to write.