- $list = array (
- array ('id' => '1','menuname' => '系统设置','parentid' => '0','sort' => '0',),
- array ('id' => '2','menuname' => '用户管理','parentid' => '0','sort' => '1',),
- array ('id' => '3','menuname' => '文章管理','parentid' => '0','sort' => '2',),
- array ('id' => '4','menuname' => '评论管理','parentid' => '0','sort' => '3',),
- array ('id' => '5','menuname' => '类别管理','parentid' => '0','sort' => '4',),
- array ('id' => '6','menuname' => '用户列表','parentid' => '1','sort' => '0',),
- array ('id' => '7','menuname' => '用户审核','parentid' => '2','sort' => '2',),
- array ('id' => '8','menuname' => '文章新增','parentid' => '3','sort' => '3',),
- array ('id' => '9','menuname' => '文章审核','parentid' => '3','sort' => '4',),
- );
- function tree(&$list,$parent_id,$deep){
- static $tree = array();
- foreach($list as $v){
- if($v['parentid'] == $parent_id){
- $v['sort'] = $deep;
- $tree[] = $v;
- tree($list,$v['id'],$deep+1);
- }
- }
- return $tree;
- }
- $result = tree($list,0,0); // 无限极分类
- echo '<pre>';print_r($result);
- echo '<pre>';
- foreach($result as $v){
- echo '|' . str_repeat('----',$v['sort']);
- echo $v['menuname'];
- echo '<br />';
- }
PHP无限极分类
最新推荐文章于 2021-04-02 12:41:31 发布