Blogger Information
Blog 175
fans 1
comment 0
visits 384409
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php递归将数组拼接为url
dxp2tq的博客
Original
1479 people have browsed it

php简单的数组递归

  1. <?php
  2. $arr = array(
  3. 'zz'=>1,
  4. 'aa' => array(
  5. 'bb' => array(
  6. 'id'=>5,
  7. 'grade'=>5,
  8. 'a'=>111
  9. ),
  10. 'cc' => array(
  11. array(
  12. "name"=>'some',
  13. "a"=>999
  14. )
  15. ),
  16. 'dd' => array(
  17. 'ctime'=>1001
  18. )
  19. ),
  20. 'ee' => array(
  21. 'ff' =>array(
  22. 'age'=> 25,
  23. 'sex'=>1
  24. )
  25. )
  26. );
  27. function ToUrlParams($arr,&$data=array()){
  28. global $str;
  29. ksort($arr);
  30. if(!is_array($arr)){
  31. echo $arr."不是数组";
  32. }else{
  33. foreach($arr as $k=>$v){
  34. if(is_array($v)){
  35. ksort($v);
  36. ToUrlParams($v);
  37. }else{
  38. $str .= $k.'='.$v.'&';
  39. }
  40. }
  41. }
  42. return substr($str,0,strlen($str)-1);
  43. }
  44. $str = ToUrlParams($arr);
  45. echo $str;
  46. 输出:
  47. a=111&grade=5&id=5&a=999&name=some&ctime=1001&age=25&sex=1&zz=1
  48. ?>
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