编写一个函数,递归遍历,实现无限分类
<?php function tree($arr,$pid=0,$level=0){ static $list = array(); foreach ($arr as $v) { //如果是顶级分类,则将其存到$list中,并以此节点为根节点,遍历其子节点 if ($v['parent_id'] == $pid) { $v['level'] = $level; $list[] = $v; tree($arr,$v['cat_id'],$level+1); } } return $list; } ?>
更多:http://www.shanhubei.com/archives/55198.html