PHP递归所有下级
2021-02-01 04:16
标签:gui string style UNC reac 重复 foreach ack function PHP递归所有下级 标签:gui string style UNC reac 重复 foreach ack function 原文地址:https://www.cnblogs.com/dawuge/p/13184989.html/**
* 获取用户下属ID集合
* @param $uid int
* @param $ids string
* @author jack
* @throws string
* @return string
*/
public function getUnderlingUIds($uid, $ids=‘‘)
{
$back = Db(‘ns_member‘,‘‘,false)->field(‘uid‘)->where(‘parent_uid‘,$uid)->select();
if (!empty($back) && is_array($back)) {
foreach ($back as $v) {
//防止当前人的ID重复去查询,形成恶性循环
if ($v[‘id‘] == $uid) {
continue;
}
$back2 = Db(‘ns_member‘,‘‘,false)->where(‘parent_uid‘,$v[‘uid‘])->count(‘uid‘);
if ($back2 > 0) {
$ids = $this->getUnderlingUIds($v[‘uid‘],$ids);
} else {
$ids .= ‘,‘.$v[‘id‘];
}
}
}
$ids = $uid.‘,‘.$ids.‘,‘;
$ids = str_replace(‘,,‘, ",", $ids);
$ids = trim($ids, ‘,‘);
return $ids;
}