&$s : 引用$s
singwa -tp6shop 8-13
直接调用
上级栏目数组下多一个list,list里有下级栏目
public static function getTree($data)
{
$items = [];
foreach ($data as $v){
$items[$v['id']] = $v; //$items索引为$v['id'],值为$v
}
$tree = [];
foreach ($items as $id => $item){
if (isset($items[$item['pid']])){ //pid不为0
$items[$item['pid']]['list'][] = &$items[$id];
}
else{
$tree[] = &$items[$id];
}
}
return $tree;
}