- function getDataTree($rows, $id='id',$pid = 'parentid',$child = 'child',$root=0) { $tree = array(); // 树
- if(is_array($rows)){
- $array = array();
- foreach ($rows as $key=>$item){
- $array[$item[$id]] =& $rows[$key];
- }
- foreach($rows as $key=>$item){
- $parentId = $item[$pid];
- if($root == $parentId){
- $tree[] =&$rows[$key];
- }else{
- if(isset($array[$parentId])){
- $parent =&$array[$parentId];
- $parent[$child][]=&$rows[$key];
- }
- }
- }
- }
- return $tree;
- }
- //该片段来自于http://www.codesnippet.cn/detail/161220138048.html
来源: http://www.codesnippet.cn/detail/161220138048.html