Blogger Information
Blog 16
fans 0
comment 0
visits 16179
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php数组循环
Leo的博客
Original
626 people have browsed it

省市区 数组,循环

循环的市区

  1. $arr = [
  2. [
  3. 'area_id' => 110000,
  4. 'area_pid' => 0,
  5. 'area_name' => '北京',
  6. 'lng' => 116.405,
  7. 'lat' => 39.905,
  8. 'son' => [
  9. [
  10. 'area_id' => 110100,
  11. 'area_pid' => 110000,
  12. 'area_name' => '北京市',
  13. 'lng' => 116.405,
  14. 'lat' => 39.905,
  15. 'son' => [
  16. [
  17. 'area_id' => 110101,
  18. 'area_pid' => 110100,
  19. 'area_name' => '东城区',
  20. 'lng' => 116.41,
  21. 'lat' => 39.9316
  22. ],
  23. [
  24. 'area_id' => 110102,
  25. 'area_pid' => 110100,
  26. 'area_name' => '西城区',
  27. 'lng' => 116.36,
  28. 'lat' => 39.9305
  29. ],
  30. [
  31. 'area_id' => 110105,
  32. 'area_pid' => 110100,
  33. 'area_name' => '朝阳区',
  34. 'lng' => 116.485,
  35. 'lat' => 39.9484
  36. ],
  37. [
  38. 'area_id' => 110106,
  39. 'area_pid' => 110100,
  40. 'area_name' => '丰台区',
  41. 'lng' => 116.286,
  42. 'lat' => 39.8585
  43. ],
  44. [
  45. 'area_id' => 110107,
  46. 'area_pid' => 110100,
  47. 'area_name' => '石景山区',
  48. 'lng' => 116.223,
  49. 'lat' => 39.9056
  50. ],
  51. [
  52. 'area_id' => 110108,
  53. 'area_pid' => 110100,
  54. 'area_name' => '海淀区',
  55. 'lng' => 116.298,
  56. 'lat' => 39.9593
  57. ],
  58. [
  59. 'area_id' => 110109,
  60. 'area_pid' => 110100,
  61. 'area_name' => '门头沟区',
  62. 'lng' => 116.101,
  63. 'lat' => 39.9404
  64. ],
  65. [
  66. 'area_id' => 110111,
  67. 'area_pid' => 110100,
  68. 'area_name' => '房山区',
  69. 'lng' => 116.143,
  70. 'lat' => 39.7479
  71. ],
  72. [
  73. 'area_id' => 110112,
  74. 'area_pid' => 110100,
  75. 'area_name' => '通州区',
  76. 'lng' => 116.657,
  77. 'lat' => 39.9097
  78. ],
  79. [
  80. 'area_id' => 110113,
  81. 'area_pid' => 110100,
  82. 'area_name' => '顺义区',
  83. 'lng' => 116.654,
  84. 'lat' => 40.1302
  85. ],
  86. [
  87. 'area_id' => 110114,
  88. 'area_pid' => 110100,
  89. 'area_name' => '昌平区',
  90. 'lng' => 116.231,
  91. 'lat' => 40.2207
  92. ],
  93. [
  94. 'area_id' => 110115,
  95. 'area_pid' => 110100,
  96. 'area_name' => '大兴区',
  97. 'lng' => 116.341,
  98. 'lat' => 39.7267
  99. ],
  100. [
  101. 'area_id' => 110116,
  102. 'area_pid' => 110100,
  103. 'area_name' => '怀柔区',
  104. 'lng' => 116.632,
  105. 'lat' => 40.316
  106. ],
  107. [
  108. 'area_id' => 110117,
  109. 'area_pid' => 110100,
  110. 'area_name' => '平谷区',
  111. 'lng' => 117.121,
  112. 'lat' => 40.1406
  113. ],
  114. [
  115. 'area_id' => 110228,
  116. 'area_pid' => 110100,
  117. 'area_name' => '密云县',
  118. 'lng' => 116.843,
  119. 'lat' => 40.3762
  120. ],
  121. [
  122. 'area_id' => 110229,
  123. 'area_pid' => 110100,
  124. 'area_name' => '延庆县',
  125. 'lng' => 115.975,
  126. 'lat' => 40.4567
  127. ]
  128. ]
  129. ]
  130. ]
  131. ],
  1. foreach($arr as $k =>$v){
  2. // print_r($v);//打印变量
  3. echo 'id:'.$v['area_id'].'--'.'省份名:'.$v['area_name'].'--'.'精度:'.$v['lng'].'--'.'维度:'.$v['lat'];
  4. // print_r($v['son']);
  5. echo'<br>';
  6. foreach($v['son'] as $kk => $vv){
  7. echo 'id:'.$vv['area_id'].'--'.'城市名:'.$vv['area_name'].'--'.'精度:'.$vv['lng'].'--'.'维度:'.$vv['lat'];
  8. echo'<br>';
  9. foreach($vv['son'] as $kkk => $vvv){
  10. echo 'id:'.$vvv['area_id'].'--'.'区名:'.$vvv['area_name'].'--'.'精度:'.$vvv['lng'].'--'.'维度:'.$vvv['lat'];
  11. echo'<br>';
  12. }
  13. }
  14. exit; // exit;停止代码,不往下进行
  15. }
  16. ?>

输出效果

  1. id:110000--省份名:北京--精度:116.405--维度:39.905
  2. id:110100--城市名:北京市--精度:116.405--维度:39.905
  3. id:110101--区名:东城区--精度:116.41--维度:39.9316
  4. id:110102--区名:西城区--精度:116.36--维度:39.9305
  5. id:110105--区名:朝阳区--精度:116.485--维度:39.9484
  6. id:110106--区名:丰台区--精度:116.286--维度:39.8585
  7. id:110107--区名:石景山区--精度:116.223--维度:39.9056
  8. id:110108--区名:海淀区--精度:116.298--维度:39.9593
  9. id:110109--区名:门头沟区--精度:116.101--维度:39.9404
  10. id:110111--区名:房山区--精度:116.143--维度:39.7479
  11. id:110112--区名:通州区--精度:116.657--维度:39.9097
  12. id:110113--区名:顺义区--精度:116.654--维度:40.1302
  13. id:110114--区名:昌平区--精度:116.231--维度:40.2207
  14. id:110115--区名:大兴区--精度:116.341--维度:39.7267
  15. id:110116--区名:怀柔区--精度:116.632--维度:40.316
  16. id:110117--区名:平谷区--精度:117.121--维度:40.1406
  17. id:110228--区名:密云县--精度:116.843--维度:40.3762
  18. id:110229--区名:延庆县--精度:115.975--维度:40.4567
Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
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