Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. //TREE
  2. array (
  3. 0 =>
  4. stdClass::__set_state(array(
  5. 'unit_id' => '5',
  6. 'localunit_id' => '5',
  7. 'name' => 'Transport',
  8. 'parent_id' => '0',
  9. 'id_shop' => '-1',
  10. 'deleted' => '0',
  11. 'parent' => '#',
  12. 'children' =>
  13. array (
  14. 0 =>
  15. stdClass::__set_state(array(
  16. 'unit_id' => '2',
  17. 'localunit_id' => '2',
  18. 'name' => 'Seri',
  19. 'parent_id' => '5',
  20. 'id_shop' => '-1',
  21. 'deleted' => '0',
  22. 'parent' => '5',
  23. 'children' =>
  24. array (
  25. 0 =>
  26. stdClass::__set_state(array(
  27. 'unit_id' => '1',
  28. 'localunit_id' => '1',
  29. 'name' => 'Cope',
  30. 'parent_id' => '2',
  31. 'id_shop' => '-1',
  32. 'deleted' => '0',
  33. 'parent' => '2',
  34. )),
  35. ),
  36. )),
  37. ),
  38. )),
  39. 1 =>
  40. stdClass::__set_state(array(
  41. 'unit_id' => '19',
  42. 'localunit_id' => '8',
  43. 'name' => 'Top',
  44. 'parent_id' => '0',
  45. 'id_shop' => '-1',
  46. 'deleted' => '0',
  47. 'parent' => '#',
  48. 'children' =>
  49. array (
  50. 0 =>
  51. stdClass::__set_state(array(
  52. 'unit_id' => '7',
  53. 'localunit_id' => '7',
  54. 'name' => 'm',
  55. 'parent_id' => '19',
  56. 'id_shop' => '-1',
  57. 'deleted' => '0',
  58. 'parent' => '19',
  59. )),
  60. ),
  61. )),
  62. )
  63.  
  64. //Iterated
  65. array (
  66. 0 =>
  67. stdClass::__set_state(array(
  68. 'unit_id' => '1',
  69. 'localunit_id' => '1',
  70. 'name' => 'Cope',
  71. 'parent_id' => '2',
  72. 'id_shop' => '-1',
  73. 'deleted' => '0',
  74. 'parent' => '2',
  75. 'group' => 1,
  76. )),
  77. 1 =>
  78. stdClass::__set_state(array(
  79. 'unit_id' => '2',
  80. 'localunit_id' => '2',
  81. 'name' => 'Seri',
  82. 'parent_id' => '5',
  83. 'id_shop' => '-1',
  84. 'deleted' => '0',
  85. 'parent' => '5',
  86. 'group' => 1,
  87. )),
  88. 2 =>
  89. stdClass::__set_state(array(
  90. 'unit_id' => '5',
  91. 'localunit_id' => '5',
  92. 'name' => 'Transport',
  93. 'parent_id' => '0',
  94. 'id_shop' => '-1',
  95. 'deleted' => '0',
  96. 'parent' => '#',
  97. 'group' => 1,
  98. )),
  99. 3 =>
  100. stdClass::__set_state(array(
  101. 'unit_id' => '7',
  102. 'localunit_id' => '7',
  103. 'name' => 'm',
  104. 'parent_id' => '19',
  105. 'id_shop' => '-1',
  106. 'deleted' => '0',
  107. 'parent' => '19',
  108. 'group' => 1,
  109. )),
  110. 4 =>
  111. stdClass::__set_state(array(
  112. 'unit_id' => '19',
  113. 'localunit_id' => '8',
  114. 'name' => 'Top',
  115. 'parent_id' => '0',
  116. 'id_shop' => '-1',
  117. 'deleted' => '0',
  118. 'parent' => '#',
  119. 'group' => 2,
  120. )),
  121. )
  122.  
  123. private $testVar=[];
  124. function flatTree($elements)
  125. {
  126. $cnt=0;
  127. foreach($elements as $element)
  128. {
  129. $cnt++;
  130. if(isset($element->children)){
  131. $this->flatTree($element->children);
  132. }
  133.  
  134. $tempElement=$element;
  135. if(isset($tempElement->children))
  136. unset($tempElement->children);
  137.  
  138. $tempElement->group=$cnt;
  139. $this->testVar[]=$tempElement;
  140. }
  141. return ;
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement