Guest User

Untitled

a guest
May 28th, 2012
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. How to iterate in multidimentional array in PHP?
  2. stdClass Object
  3. (
  4. [37] => Array
  5. (
  6. [term_id] => 37
  7. [name] => Files
  8. [parent] => 0
  9. [38] => Array
  10. (
  11. [term_id] => 38
  12. [name] => Downloads
  13. [parent] => 37
  14. )
  15.  
  16. )
  17.  
  18. [29] => Array
  19. (
  20. [term_id] => 29
  21. [name] => Articles
  22. [parent] => 0
  23. [36] => Array
  24. (
  25. [term_id] => 36
  26. [name] => General
  27. [parent] => 29
  28. )
  29.  
  30. [35] => Array
  31. (
  32. [term_id] => 35
  33. [name] => WordPress
  34. [parent] => 29
  35. )
  36.  
  37. [34] => Array
  38. (
  39. [term_id] => 34
  40. [name] => Php, Sql
  41. [parent] => 29
  42. )
  43.  
  44. )
  45.  
  46. [1] => Array
  47. (
  48. [term_id] => 1
  49. [name] => Uncategorized
  50. [parent] => 0
  51. )
  52.  
  53. )
  54.  
  55. Files
  56. Downloads
  57. Articles
  58. General
  59. WordPress
  60. Php, Sql
  61. Uncategorized
  62.  
  63. $categories = get_array_content(); // Return the above data
  64.  
  65. print_category_tree($categories);
  66.  
  67. function print_category_tree(&$c)
  68. {
  69. foreach($c as $cat)
  70. {
  71. ?>
  72. <label>
  73. <input type="checkbox" value="<?php echo $cat['term_id']; ?>" /> <?php echo $cat['name']; ?>
  74. </label>
  75. <br />
  76. <?php
  77.  
  78. foreach($cat as $categ)
  79. {
  80. if(is_array($categ))
  81. {
  82. print_category_tree($categ);
  83. }
  84. }
  85. }
  86. }
  87.  
  88. print_category_tree($categ, $forum_id);
  89.  
  90. function print_category_tree(&$c)
  91.  
  92. function print_category_tree($c)
Advertisement
Add Comment
Please, Sign In to add comment