无限极分类

<?php

//数据表

// CREATE TABLE CATEGORY(
// cat_id smallint unsigned not null anto_increment primary key comment '类名',
// cat_name VARCHAT(30) NOT NULL DEFAULT '' COMMENT '类别名称',
// parent_id SMALLINT UNSIGNED NOT NULL DEFAULT 0 COMMENT '类别父Id',
// )engine=Myisam charset=utf8 comment '无限极分类数据表';

function tree($arr,$pid=0,$level=0){
static $list =array();
foreach($arr as $v){
if($v['parent_id']==$pid){
$v['level']=$level;
$list[]=$v;
tree($arr,$v['cat_id'],$level+1);
}
}
return $list;
}

原文地址:https://www.cnblogs.com/hmetoer2017/p/6250610.html