查找下级所有数据

admin2年前Laravel892

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;
}

相关文章

微信支付V2

   public static function unifiedorder($openid, $out_trade_no, $total_fee, $notify)...

百度浏览器中视频悬浮

  <video class="html5-video"                poster=...

解密微信绑定的手机号

public function mobile() { $code = request()->input('code'); if (!$code) { return $this-&...

微信开放平台-扫码登录

public function wx_info(){    $code = request()->input('code');    if...

压缩图片

public static function size($id, $img) { try { list($width, $height, $img_type, $attr) = @getimages...

PHP 严格类型

只需在 PHP 代码文件的开头加上declare(strict_types = 1);这一行魔法代码,就能开启严格类型检查之旅。...