Blogger Information
Blog 47
fans 0
comment 3
visits 44840
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
遍历数组,输出省市区名称
江流
Original
862 people have browsed it

数组数据存储在area.php文件中。

  1. include "area.php"; //导入文件
  2. // 第一层循环,省级名称输出
  3. foreach($arr as $province){
  4. echo "<h2>". $province['area_name']."</h2>";
  5. // 第二层循环,城市名称输出
  6. foreach($province['son'] as $city){
  7. echo "<h4>". $city['area_name']."</h4>";
  8. // 第三层循环,县区名称输出
  9. foreach($city['son'] as $county){
  10. echo $county['area_name'];
  11. echo "&nbsp;";
  12. }
  13. }
  14. echo "<hr>";
  15. }
  • 效果

  • 使用print_r()
  1. // 使用print_r()输出石家庄市及县区的数据
  2. print_r($arr[2]['son'][0]);
  • 效果

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