父分类parentid=0,子分类的parentid=父id。 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;}
复制代码
