function make_tree($list,$pk='id',$pid='pid',$child='_child',$root=0){
$tree=array();
$packData=array();
foreach ($list as $data) {
$packData[$data[$pk]] = $data;
}
foreach ($packData as $key =>$val){
if($val[$pid]==$root){
$tree[]=& $packData[$key];
}else{
$packData[$val[$pid]][$child][]=& $packData[$key];
}
}
return $tree;
}
function list_to_tree($list, $pk='id', $pid = 'pid', $child = '_child', $root = 0) {
$tree = array();
if(is_array($list)) {
$refer = array();
foreach ($list as $key => $data) {
$refer[$data[$pk]] =& $list[$key];
}
foreach ($list as $key => $data) {
$parentId = $data[$pid];
if ($root == $parentId) {
$tree[] =& $list[$key];
}else{
if (isset($refer[$parentId])) {
$parent =& $refer[$parentId];
$parent[$child][] =& $list[$key];
}
}
}
}
return $tree;
}
function make_tree1($list,$pk='id',$pid='pid',$child='_child',$root=0){
$tree=array();
foreach($list as $key=> $val){
if($val[$pid]==$root){
unset($list[$key]);
if(! empty($list)){
$child=make_tree1($list,$pk,$pid,$child,$val[$pk]);
if(!empty($child)){
$val['_child']=$child;
}
}
$tree[]=$val;
}
}
return $tree;
}