省市区 数组,循环
循环的市区
$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
],
[
'area_id' => 110105,
'area_pid' => 110100,
'area_name' => '朝阳区',
'lng' => 116.485,
'lat' => 39.9484
],
[
'area_id' => 110106,
'area_pid' => 110100,
'area_name' => '丰台区',
'lng' => 116.286,
'lat' => 39.8585
],
[
'area_id' => 110107,
'area_pid' => 110100,
'area_name' => '石景山区',
'lng' => 116.223,
'lat' => 39.9056
],
[
'area_id' => 110108,
'area_pid' => 110100,
'area_name' => '海淀区',
'lng' => 116.298,
'lat' => 39.9593
],
[
'area_id' => 110109,
'area_pid' => 110100,
'area_name' => '门头沟区',
'lng' => 116.101,
'lat' => 39.9404
],
[
'area_id' => 110111,
'area_pid' => 110100,
'area_name' => '房山区',
'lng' => 116.143,
'lat' => 39.7479
],
[
'area_id' => 110112,
'area_pid' => 110100,
'area_name' => '通州区',
'lng' => 116.657,
'lat' => 39.9097
],
[
'area_id' => 110113,
'area_pid' => 110100,
'area_name' => '顺义区',
'lng' => 116.654,
'lat' => 40.1302
],
[
'area_id' => 110114,
'area_pid' => 110100,
'area_name' => '昌平区',
'lng' => 116.231,
'lat' => 40.2207
],
[
'area_id' => 110115,
'area_pid' => 110100,
'area_name' => '大兴区',
'lng' => 116.341,
'lat' => 39.7267
],
[
'area_id' => 110116,
'area_pid' => 110100,
'area_name' => '怀柔区',
'lng' => 116.632,
'lat' => 40.316
],
[
'area_id' => 110117,
'area_pid' => 110100,
'area_name' => '平谷区',
'lng' => 117.121,
'lat' => 40.1406
],
[
'area_id' => 110228,
'area_pid' => 110100,
'area_name' => '密云县',
'lng' => 116.843,
'lat' => 40.3762
],
[
'area_id' => 110229,
'area_pid' => 110100,
'area_name' => '延庆县',
'lng' => 115.975,
'lat' => 40.4567
]
]
]
]
],
foreach($arr as $k =>$v){
// print_r($v);//打印变量
echo 'id:'.$v['area_id'].'--'.'省份名:'.$v['area_name'].'--'.'精度:'.$v['lng'].'--'.'维度:'.$v['lat'];
// print_r($v['son']);
echo'<br>';
foreach($v['son'] as $kk => $vv){
echo 'id:'.$vv['area_id'].'--'.'城市名:'.$vv['area_name'].'--'.'精度:'.$vv['lng'].'--'.'维度:'.$vv['lat'];
echo'<br>';
foreach($vv['son'] as $kkk => $vvv){
echo 'id:'.$vvv['area_id'].'--'.'区名:'.$vvv['area_name'].'--'.'精度:'.$vvv['lng'].'--'.'维度:'.$vvv['lat'];
echo'<br>';
}
}
exit; // exit;停止代码,不往下进行
}
?>
输出效果
id:110000--省份名:北京--精度:116.405--维度:39.905
id:110100--城市名:北京市--精度:116.405--维度:39.905
id:110101--区名:东城区--精度:116.41--维度:39.9316
id:110102--区名:西城区--精度:116.36--维度:39.9305
id:110105--区名:朝阳区--精度:116.485--维度:39.9484
id:110106--区名:丰台区--精度:116.286--维度:39.8585
id:110107--区名:石景山区--精度:116.223--维度:39.9056
id:110108--区名:海淀区--精度:116.298--维度:39.9593
id:110109--区名:门头沟区--精度:116.101--维度:39.9404
id:110111--区名:房山区--精度:116.143--维度:39.7479
id:110112--区名:通州区--精度:116.657--维度:39.9097
id:110113--区名:顺义区--精度:116.654--维度:40.1302
id:110114--区名:昌平区--精度:116.231--维度:40.2207
id:110115--区名:大兴区--精度:116.341--维度:39.7267
id:110116--区名:怀柔区--精度:116.632--维度:40.316
id:110117--区名:平谷区--精度:117.121--维度:40.1406
id:110228--区名:密云县--精度:116.843--维度:40.3762
id:110229--区名:延庆县--精度:115.975--维度:40.4567