Blogger Information
Blog 3
fans 0
comment 0
visits 3439
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php无限极分类
航航的博客
Original
1455 people have browsed it

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;

    }


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post