function getTree($data, $pId, $level=0)
{
$tree = '';
foreach($data as $k => $v)
{
if($v['teacherbianhao'] == $pId)
{ //父亲找到儿子
unset($data[$k]);//注销当前节点数据,减少已无用的遍历
$v['teacherbianhao'] = getTree($data, $v['bianhao'],$level+1);
$tree[] = $v;
}
}
return $tree;
}
//这个位置带入参数
$tree = getTree($data, $bh,0);
function procHtml($tree)
{
$html = '';
foreach($tree as $t)
{
if($t['teacherbianhao'] == '')
{
$html .= "<li>{$t['nickname']}{$t['bianhao']}</li>";
}
else
{
// $html .= "<li>".$t['nickname'].$t['bianhao']."共".$t['level']."人";
$html .= "<li>".$t['nickname'].$t['bianhao'];
$html .= procHtml($t['teacherbianhao']);
$html = $html."</li>";
}
}
return $html ? '<ul>'.$html.'</ul>' : $html ;
}
echo procHtml($tree);