Description: The parent array contains a unique pid,pid by calling the M-layer to get the contents of the sub-array, requiring the parent and child arrays to have the same key and then merging them together
Code
foreach($parentArray as $v){ $a['id']=$v['pid']; $a['name'] =$v['name']; ... $array[] =$a; $childContent = $m->getChildContent($v['pid']); foreach($childContent as $v2){ $b['id']=$v2['cid']; $b['name']=$v2['cname']; ... $array2[]=$b; }}
I want to make the output such a format
array[0]{ $array里的内容, $array2里的内容}array[1]{ $array, $array2,}
Because it is an infinite rating, you want to combine the first and child array groups of the foreach traversal array into an array,
Final output style:
Parent Parents Column
--child Sub-column
Parent Parents Column
--child Sub-column
Parent Parents Column
--child Sub-column
.....
Reply content:
Description: The parent array contains a unique pid,pid by calling the M-layer to get the contents of the sub-array, requiring the parent and child arrays to have the same key and then merging them together
Code
foreach($parentArray as $v){ $a['id']=$v['pid']; $a['name'] =$v['name']; ... $array[] =$a; $childContent = $m->getChildContent($v['pid']); foreach($childContent as $v2){ $b['id']=$v2['cid']; $b['name']=$v2['cname']; ... $array2[]=$b; }}
I want to make the output such a format
array[0]{ $array里的内容, $array2里的内容}array[1]{ $array, $array2,}
Because it is an infinite rating, you want to combine the first and child array groups of the foreach traversal array into an array,
Final output style:
Parent Parents Column
--child Sub-column
Parent Parents Column
--child Sub-column
Parent Parents Column
--child Sub-column
.....
I don't know if you're talking about a situation that is similar to an infinite classification.
If parent and child are placed on the same table (should also be)
If there's only two floors, that's what I usually do.
Then the query is sorted by PID
ORDER BY `pid` ASC
Then iterate through the array
$result = array();foreach($data as $v) { if($v['pid'] == 0) { $result[$v['id']] = $v; continue; } $result[$v['pid']]['chlid'][] = $v;}var_dump($result);
If you need three layers, for example,
array( array( 'id', 'pid', 'child' => array( array( 'id', 'pid', 'child' => array( ... ), ), ), ),)
In that case, I find this way a bit of trouble.
Resources:http://www.cnblogs.com/yangmanyan/archive/2011/06/16/2082963.html
Sorry to update, the results from the database query, even if the field type is integer type, query out is also a string.
So it should be $v['pid'] == 0
or $v['pid'] === '0'
.
To be converted to: o:27: "Guzzlehttp\cookie\cookiejar": 2: