/** *参 数:$list 分类数据 $pid父id *功 能:无限级分类 */function Tree(&$list , $pid = 0 , $level = 0 , $html = '--'){ static $tree = array(); foreach($list as $v) { if($v['parent_did'] == $pid) { $v['level'] = $level; $v['html'] = str_repeat($html, $level); $tree[] = $v; Tree($list, $v['did'], $level + 1, $html); } } return $tree;} $area = array( array('did'=>1,'name'=>'安徽','parent_did'=>0), array('did'=>2,'name'=>'合肥','parent_did'=>1), array('did'=>3,'name'=>'枞阳','parent_did'=>5), array('did'=>4,'name'=>'浦东','parent_did'=>7), array('did'=>5,'name'=>'安庆','parent_did'=>1), array('did'=>6,'name'=>'杨浦','parent_did'=>7), array('did'=>7,'name'=>'上海','parent_did'=>0), array('did'=>8,'name'=>'肥东','parent_did'=>2), array('did'=>9,'name'=>'唐镇','parent_did'=>4) ); $tree = Tree($area,0,1);