Blogger Information
Blog 175
fans 1
comment 0
visits 384391
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php简单的数组递归
dxp2tq的博客
Original
1405 people have browsed it

php简单的数组递归

  1. $arr = array(
  2. 'aa' => array(
  3. 'bb' => array(
  4. 'id'=>5,
  5. 'grade'=>5
  6. ),
  7. 'cc' => array(
  8. "name"=>'some'
  9. ),
  10. 'dd' => array(
  11. 'ctime'=>1001
  12. )
  13. ),
  14. 'ee' => array(
  15. 'ff' =>array(
  16. 'age'=> 25,
  17. 'sex'=>1
  18. )
  19. )
  20. );
  1. function a($arr){
  2. if(!is_array($arr)){
  3. echo $arr."\n";
  4. }else
  5. foreach($arr as $k=>$v){
  6. if(is_array($v)){
  7. echo "键是$k"."\n";
  8. echo a($v)."\n";
  9. }else{
  10. echo "键是$k"."\n";
  11. echo $v."\n";
  12. }
  13. }
  14. }
  15. a($arr);

结果
键是aa
键是bb
键是id
5
键是grade
5

键是cc
键是name
some

键是dd
键是ctime
1001

键是ee
键是ff
键是age
25
键是sex
1

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