public function subtree($arr,$id=0,$lev=1) {
static $subs = array(); //子孙数组
foreach ($arr as $v) {
if ($v['pid'] == $id) {
$v['lev'] = $lev;
$subs[] = $v;
$this->subtree($arr,$v['tag_id'],$lev+1);
}
}
return $subs;
}
public static function recursive_make_tree($list, $pk = 'tag_id', $pid = 'pid', $child = '_child', $root = 0)
{
$tree = [];
foreach ($list as $key => $val) {
if ($val[$pid] == $root) {
//获取当前$pid所有子类
unset($list[$key]);
if (!empty($list)) {
$child = self::recursive_make_tree($list, $pk, $pid, $child, $val[$pk]);
if (!empty($child)) {
$val['_child'] = $child;
}
}
$tree[] = $val;
}
}
return $tree;
}
/*递归查询所有下级用户*/
function GetTeamMember($members, $mid) {
$Teams=array();//最终结果
$mids=array($mid);//第一次执行时候的用户id
do {
$othermids=array();
$state=false;
foreach ($mids as $valueone) {
foreach ($members as $key => $valuetwo) {
if($valuetwo['parentId']==$valueone){
$Teams[]=$valuetwo['_ID'];//找到我的下级立即添加到最终结果中
$othermids[]=$valuetwo['_ID'];//将我的下级id保存起来用来下轮循环他的下级
array_splice($members,$key,1);//从所有会员中删除他
$state=true;
}
}
}
$mids=$othermids;//foreach中找到的我的下级集合,用来下次循环
} while ($state==true);
return $Teams;
}