Correcting teacher:PHPz
Correction status:qualified
Teacher's comments:
$arr = $arr = [
[
'area_id' => 110000,
'area_pid' => 0,
'area_name' => '北京',
'lng' => 116.405,
'lat' => 39.905,
'son' => [
[
'area_id' => 110100,
'area_pid' => 110000,
'area_name' => '北京市',
'lng' => 116.405,
'lat' => 39.905,
'son' => [
[
'area_id' => 110101,
'area_pid' => 110100,
'area_name' => '东城区',
'lng' => 116.41,
'lat' => 39.9316
],
[
'area_id' => 110102,
'area_pid' => 110100,
'area_name' => '西城区',
'lng' => 116.36,
'lat' => 39.9305
]
//具体数据省略。。。
]
]
]
]
//, 具体数据省略。。。
];
$txt=" ";//输出多个空格
$space = str_replace(chr(32),' ',$txt);
foreach ($arr as $key => $value) {//循环省
echo $value['area_name']."<br>"; //输出省名称
foreach ($value['son'] as $k => $v) {//循环市
echo $space.$v['area_name']."<br>";//输出市名称
foreach ($v['son'] as $k1 => $v1) {//循环区县
echo $space.$space.$v1['area_name']."<br>"; //输出区县名称
}
}
}
运行结果: