bwin必赢棋牌PHP不使用递归的无限级分类简单实例_php实例_脚本之家,创建无限极分类树型结构的简单方法_php实例_脚本之家

无须递归达成Infiniti级分类,轻巧测验了下质量比递归稍好一丝丝点,但写得太复杂了,依旧递归简单方便点

先上效果图

1, 'pid'=>0, 'deep'=>0, 'name'=>'test1'), array('id'=>2, 'pid'=>1, 'deep'=>1, 'name'=>'test2'), array('id'=>3, 'pid'=>0, 'deep'=>0, 'name'=>'test3'), array('id'=>4, 'pid'=>2, 'deep'=>2, 'name'=>'test4'), array('id'=>5, 'pid'=>2, 'deep'=>2, 'name'=>'test5'), array('id'=>6, 'pid'=>0, 'deep'=>0, 'name'=>'test6'), array('id'=>7, 'pid'=>2, 'deep'=>2, 'name'=>'test7'), array('id'=>8, 'pid'=>5, 'deep'=>3, 'name'=>'test8'), array('id'=>9, 'pid'=>3, 'deep'=>2, 'name'=>'test9'),);function resolve { $newList = $manages = $deeps = $inDeeps = array(); foreach  { $newList[$row['id']] = $row; } $list = null; foreach  { if (! isset($manages[$row['pid']]) || ! isset($manages[$row['pid']]['children'][$row['id']])) { if ($row['pid'] > 0 && ! isset($manages[$row['pid']]['children'])) $manages[$row['pid']] = $newList[$row['pid']]; $manages[$row['pid']]['children'][$row['id']] = $row; } if (! isset($inDeeps[$row['deep']]) || ! in_array($row['id'], $inDeeps[$row['deep']])) { $inDeeps[$row['deep']][] = array($row['pid'], $row['id']); } } krsort; array_shift; foreach ($inDeeps as $deep => $ids) { foreach  { // 存在子栏目的进行转移 if (isset { $manages[$m[0]]['children'][$m[1]] = $manages[$m[1]]; $manages[$m[1]] = null; unset; } } } return $manages[0]['children'];}

function resolve2 { $manages = array(); foreach  { if  { $manages[$row['id']] = $row; $children = resolve2; $children && $manages[$row['id']]['children'] = $children; } } return $manages;}

少年老产品分类其实便是一流分类,二级分类也叫作一流分类的子分类,在这里个底蕴上,子分类还足以具备子分类,这样就结成了Infiniti极分类。

如上那篇PHP不行使递归的无比级分类轻巧实例就是我共享给我们的全体内容了,希望能给大家三个参照,也期望大家多多指教脚本之家。

接下去看具体落到实处的代码:

风度翩翩、在调节器中按字段查询,查询出装有分类消息(id:该分类的ID值,cate_name:该分类的称号,pid:父ID,sorts:为展现标题顺序排序做盘算,可不写。)

public function cate_display; $field = array('id','cate_name','pid','sorts'); $list = $cate->allCategory; $this->assign; $this->display(); }

二、模型中的代码

在对应调节器的模子中创设多个艺术

1.查询全体分类音讯,并调用生成分类树方法:

发表评论

电子邮件地址不会被公开。 必填项已用*标注