欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

分类树

程序员文章站 2022-10-06 22:28:28
/** * 分类树function * @return [type] [description] */function tree($data, $pid = 0,$level = 1){ static $treeList = array(); foreach ($data as $v) { if ( ......
/**
* 分类树function
* @return [type] [description]
*/
function tree($data, $pid = 0,$level = 1)
{
static $treeList = array();
foreach ($data as $v) {
if ($v['pid'] == $pid) {
$v['level']=$level;
$treeList[] = $v;//将结果装到$treeList中
tree($data, $v['id'],$level+1);
}
}
return $treeList;
}