Blogger Information
Blog 20
fans 0
comment 1
visits 13139
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php数组循环
zg的php学习
Original
656 people have browsed it

数组循环

省市县的循环

  1. $arr = $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. ]
  32. ]
  33. ]
  34. ]
  35. //, 具体数据省略。。。
  36. ];
  37. $txt=" ";//输出多个空格
  38. $space = str_replace(chr(32),' ',$txt);
  39. foreach ($arr as $key => $value) {//循环省
  40. echo $value['area_name']."<br>"; //输出省名称
  41. foreach ($value['son'] as $k => $v) {//循环市
  42. echo $space.$v['area_name']."<br>";//输出市名称
  43. foreach ($v['son'] as $k1 => $v1) {//循环区县
  44. echo $space.$space.$v1['area_name']."<br>"; //输出区县名称
  45. }
  46. }
  47. }

运行结果:
运行结果

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