php四级联动

省市区四级联动

 		$handle = Db::name('dev_region');

        //查询所有一级数据
        $all = (clone $handle)->where('level',1)->select()->toArray();

        //查找下级
        foreach($all as &$v){
            $first = (clone $handle)->where('parent_id',$v['id'])->select()->toArray();
            $v['children'] = $first;
            foreach($v['children'] as &$val){
                $second = (clone $handle)->where('parent_id',$val['id'])->select()->toArray();
                $val['children'] = $second;
                foreach($val['children'] as &$value){
                    $three = (clone $handle)->where('parent_id',$value['id'])->select()->toArray();
                    $value['children'] = $three;
                }
            }

        }

你可能感兴趣的:(php,开发语言)