Blogger Information
Blog 10
fans 0
comment 0
visits 4980
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
10月09日作业 foreach多级循环写法
鬼才哥-秋兜
Original
559 people have browsed it

一级循环写法

  1. //一级循环成功
  2. foreach($arr as $key=>$value){
  3. echo $value['area_id'];
  4. echo '--';
  5. echo $value['area_pid'];
  6. echo '--';
  7. echo $value['area_name'];
  8. echo '--';
  9. echo $value['lng'];
  10. echo '--';
  11. echo $value['lat'];
  12. echo '<hr>';
  13. }
  14. //打印输出
  15. print_r($arr);

二级循环写法

  1. //二级循环成功
  2. foreach($arr as $key => $value){
  3. foreach($value as $key_two => $value_two){
  4. echo $value['area_id'];
  5. echo '--';
  6. echo $value['area_pid'];
  7. echo '--';
  8. echo $value['area_name'];
  9. echo '--';
  10. echo $value['lng'];
  11. echo '--';
  12. echo $value['lat'];
  13. echo '<hr>';
  14. }
  15. }
  16. //打印输出
  17. print_r($arr);

三级循环写法

  1. //三级循环成功
  2. foreach($arr as $key => $value){
  3. foreach($value as $key_a => $value_a){
  4. foreach($value as $key_b => $value_b){
  5. echo $value['area_id'];
  6. echo '--';
  7. echo $value['area_pid'];
  8. echo '--';
  9. echo $value['area_name'];
  10. echo '--';
  11. echo $value['lng'];
  12. echo '--';
  13. echo $value['lat'];
  14. echo '<hr>';
  15. }
  16. }
  17. }
  18. //打印输出
  19. print_r($arr);

四级循环写法

  1. //四级循环成功
  2. foreach($arr as $key => $value){
  3. foreach($value as $key_a => $value_a){
  4. foreach($value as $key_b => $value_b){
  5. foreach($value as $key_c => $value_c){
  6. echo $value['area_id'];
  7. echo '--';
  8. echo $value['area_pid'];
  9. echo '--';
  10. echo $value['area_name'];
  11. echo '--';
  12. echo $value['lng'];
  13. echo '--';
  14. echo $value['lat'];
  15. echo '<hr>';
  16. }
  17. }
  18. }
  19. }
  20. //打印输出
  21. print_r($arr);

五级循环写法

  1. //五级循环成功
  2. foreach($arr as $key => $value){
  3. foreach($value as $key_a => $value_a){
  4. foreach($value as $key_b => $value_b){
  5. foreach($value as $key_c => $value_c){
  6. foreach($value as $key_d => $value_d){
  7. echo $value['area_id'];
  8. echo '--';
  9. echo $value['area_pid'];
  10. echo '--';
  11. echo $value['area_name'];
  12. echo '--';
  13. echo $value['lng'];
  14. echo '--';
  15. echo $value['lat'];
  16. echo '<hr>';
  17. }
  18. }
  19. }
  20. }
  21. }
  22. //打印输出
  23. print_r($arr);
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