Blogger Information
Blog 18
fans 0
comment 0
visits 10940
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
foreach循环
手机用户1631860753
Original
832 people have browsed it

一.foreach循环

1.用echo输出单值

  • 代码:
    echo $aaa[2]['area_id']. '--' .$aaa[1]['area_name'];
  • 输出id和名称
  • 效果:

2.用print_r输出数组

  • 代码:
    1. print_r($aaa);//打印所有数组
    2. print_r(#aaa[0]);//打印当前数组
    3. print_r($aaa [0]['son'] [0]['son'] );//打印当前数组下所有下级数组
  • 打印当前数组效果图:

3.省市区循环

  • 代码
    1. foreach ($aaa as $k1 => $v1) {
    2. echo '编号:';
    3. echo $k1;
    4. echo ',--id是:';
    5. echo $v1['area_id'];
    6. echo ',--省份名:';
    7. echo $v1['area_name'];
    8. echo ',--精度:';
    9. echo $v1['lng'];
    10. echo ',--维度:';
    11. echo $v1['lat'];
    12. echo '<br>';
    13. echo '<hr>';
    14. foreach ($v1['son'] as $k2 => $v2) {
    15. echo '编号:';
    16. echo $k2;
    17. echo '--id是:';
    18. echo $v2['area_id'];
    19. echo '--城市名:';
    20. echo $v2['area_name'];
    21. echo '--精度:';
    22. echo $v2['lng'];
    23. echo '--维度:';
    24. echo $v2['lat'];
    25. echo '<hr>';
    26. foreach($v2['son'] as $k3 => $v3){
    27. echo '编号:'.$k3 . '--id是:' .$v3['area_id']. '--市区名:' .$v3['area_name']. '--精度:' .$v3['lng']. '--维度:' .$v3['lat'];
    28. echo '<br>';
    29. }
    30. echo '<hr>';
    31. }
    32. };
  • 部分效果图:
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