PHP实现无限级分类
作者:互联网
function getTree($data) {
$items = [];
foreach ($data as $v){
$items[$v['id']] = $v; // $items[1] =
}
$tree = array(); //格式化好的树
foreach ($items as $item)
if (isset($items[$item['pid']]))
$items[$item['pid']]['son'][] = &$items[$item['id']];
else
$tree[] = &$items[$item['id']];
return $tree;
}
标签:items,pid,分类,tree,item,无限,foreach,PHP,id 来源: https://www.cnblogs.com/itzhangxuhui/p/15732812.html