三级联动地址树状数据

字数 119阅读 68

//查询三级联动的地址信息树状结构--未应用

public static functiongetRegionAddressTree()

{

$addressList=self::find()->with([

'children',

'children.children',

])->where([self::tableName().'.parent_id'=>1])->asArray()

->all();

$provinceList= [];

foreach($addressListas$province) {

$cityList= [];

if(!empty($province['children'])) {

foreach($province['children']as$city) {

$districtlist= [];

if(!empty($city['children'])) {

foreach($city['children']as$district) {

$districtlist[] = [

'district_id'=>$district['region_id'],

'district_name'=>$district['region_name'],

];

}

}

$cityList[] = [

'city_id'=>$city['region_id'],

'city_name'=>$city['region_name'],

'district_list'=>$districtlist,

];

}

}

$provinceList[] = [

'province_id'=>$province['region_id'],

'province_name'=>$province['region_name'],

'city_list'=>$cityList,

];

}

return$provinceList;

}


推荐阅读更多精彩内容