fork download
  1. <?php
  2.  
  3. function recusive_list($items, $c) {
  4. $c += 1;
  5. $text = '';
  6. if (is_object($items))
  7. $items = get_object_vars($items);
  8. foreach ($items as $key => $item) {
  9. if(!is_array($item))
  10. $text .= str_repeat('*', $c) . ' ' .$key. ' - ' .$item. "\n";
  11. else
  12. $text .= recusive_list($item, $c);
  13. }
  14. return $text;
  15. }
  16.  
  17. $items = [
  18. [
  19. 'href' => 'www.item1',
  20. 'name' => 'Item1',
  21. 'childs' => [
  22. [
  23. 'href' => 'www.item1.1',
  24. 'name' => 'Item1.1',
  25. 'childs' => []
  26. ]
  27. ]
  28. ],
  29. [
  30. 'href' => 'www.item2',
  31. 'name' => 'Item2',
  32. 'childs' => [
  33. [
  34. 'href' => 'www.item2.1',
  35. 'name' => 'Item2.1',
  36. 'childs' => [
  37. [
  38. 'href' => 'www.item2.1.1',
  39. 'name' => 'Item2.1.1',
  40. 'childs' => []
  41. ],
  42. [
  43. 'href' => 'www.item2.1.2',
  44. 'name' => 'Item2.1.2',
  45. 'childs' => [
  46. [
  47. 'href' => 'www.item2.1.2.1',
  48. 'name' => 'Item2.1.2.1',
  49. 'childs' => []
  50. ]
  51. ]
  52. ]
  53. ]
  54. ]
  55. ]
  56. ],
  57. [
  58. 'href' => 'www.item3',
  59. 'name' => 'Item3',
  60. 'childs' => []
  61. ],
  62. ];
  63.  
  64. echo recusive_list($items, 0);
Success #stdin #stdout 0s 82560KB
stdin
Standard input is empty
stdout
** href - www.item1
** name - Item1
**** href - www.item1.1
**** name - Item1.1
** href - www.item2
** name - Item2
**** href - www.item2.1
**** name - Item2.1
****** href - www.item2.1.1
****** name - Item2.1.1
****** href - www.item2.1.2
****** name - Item2.1.2
******** href - www.item2.1.2.1
******** name - Item2.1.2.1
** href - www.item3
** name - Item3