查找下级所有数据

admin2年前Laravel728

public function bottom($mid = 3)
{
   $members = DB::select('select id,parent_id,`level` from member where status= 1  and parent_id >= 0');
   $Teams = array();//最终结果
   $mids = array($mid);//第一次执行时候的用户id
   do {
       $othermids = array();
       $state = false;
       foreach ($mids as $valueone) {
           foreach ($members as $key => $valuetwo) {
               if ($valuetwo->parent_id == $valueone) {
                   $Teams[] = $valuetwo->id;//找到我的下级立即添加到最终结果中
                   $othermids[] = $valuetwo->id;//将我的下级id保存起来用来下轮循环他的下级
                   $state = true;
               }
           }
       }
       $mids = $othermids;//foreach中找到的我的下级集合,用来下次循环
   } while ($state == true);
   array_push($Teams, $mid);
   return $Teams;
}

相关文章

excel 导出

header("Content-Type: application/vnd.ms-excel; name='excel'"); header("Content-Disposition:atta...

抖音小程序码

public function dyqrcode($uid){    $url = "https://open.douyin.com/api/apps/v1/qrcode...

批量处理数据

   public function index44()    {        $domain = request(...

修改密码

public function setpass(){    $mobile = request()->input('mobile');   &nbs...

用户注册账号

public function register(){    $mobile = request()->input('mobile');   &nb...

php 优化

使用 gc_collect_cycles() 强制进行垃圾回收 PHP 的垃圾回收机制会自动释放不再使用的变量所占用的内存。然而,在某些情况下,尤其是在长时间运行的脚本(如 CLI...