验证中...
Languages: PHP
Categories: 微信开发
Latest update 2019-01-19 08:01
gistfile1.txt
Raw Copy
/**
* 根据resource列表生成树结构
* array $list
*/
public static function buildTree($list,$pid='',$p_name='') {
if(empty($pid) || empty($p_name)) return [];
$map = $tree = [];
//数据的ID名生成新的引用索引树
foreach ($list as &$it){
$map[$it[$pid]] = &$it;
}
foreach ($list as &$it){
$parent = &$map[$it[$p_name]];
if($parent) {
$parent['child'][] = &$it;
}else{
$tree[] = &$it;
}
if(!isset($it['child']))
$it['child'] = [];
}
return $tree;
}

Comment list( 0 )

You need to Sign in for post a comment

Help Search