php 15行解决无限极获取子节点,(非递归,已亲测)

//member:总数据(id自增顺序)

//mid 要查的id

 

public function GetSonMember($members, $mid) {
$teams=array();
$teams[$mid] = '';
foreach ($members as $k=>$v) {
if ( isset($teams[$v['pid']]) ) {
$teams[$v['id'] ] = '';
unset($members[$k]);
} else {
unset($members[$k]);
}
}
//因为获取的是第一个会员下级,所以删除第一个会员
unset($teams[$mid]);
return array_keys($teams);
}

你可能感兴趣的:(php)