Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //TREE
- array (
- 0 =>
- stdClass::__set_state(array(
- 'unit_id' => '5',
- 'localunit_id' => '5',
- 'name' => 'Transport',
- 'parent_id' => '0',
- 'id_shop' => '-1',
- 'deleted' => '0',
- 'parent' => '#',
- 'children' =>
- array (
- 0 =>
- stdClass::__set_state(array(
- 'unit_id' => '2',
- 'localunit_id' => '2',
- 'name' => 'Seri',
- 'parent_id' => '5',
- 'id_shop' => '-1',
- 'deleted' => '0',
- 'parent' => '5',
- 'children' =>
- array (
- 0 =>
- stdClass::__set_state(array(
- 'unit_id' => '1',
- 'localunit_id' => '1',
- 'name' => 'Cope',
- 'parent_id' => '2',
- 'id_shop' => '-1',
- 'deleted' => '0',
- 'parent' => '2',
- )),
- ),
- )),
- ),
- )),
- 1 =>
- stdClass::__set_state(array(
- 'unit_id' => '19',
- 'localunit_id' => '8',
- 'name' => 'Top',
- 'parent_id' => '0',
- 'id_shop' => '-1',
- 'deleted' => '0',
- 'parent' => '#',
- 'children' =>
- array (
- 0 =>
- stdClass::__set_state(array(
- 'unit_id' => '7',
- 'localunit_id' => '7',
- 'name' => 'm',
- 'parent_id' => '19',
- 'id_shop' => '-1',
- 'deleted' => '0',
- 'parent' => '19',
- )),
- ),
- )),
- )
- //Iterated
- array (
- 0 =>
- stdClass::__set_state(array(
- 'unit_id' => '1',
- 'localunit_id' => '1',
- 'name' => 'Cope',
- 'parent_id' => '2',
- 'id_shop' => '-1',
- 'deleted' => '0',
- 'parent' => '2',
- 'group' => 1,
- )),
- 1 =>
- stdClass::__set_state(array(
- 'unit_id' => '2',
- 'localunit_id' => '2',
- 'name' => 'Seri',
- 'parent_id' => '5',
- 'id_shop' => '-1',
- 'deleted' => '0',
- 'parent' => '5',
- 'group' => 1,
- )),
- 2 =>
- stdClass::__set_state(array(
- 'unit_id' => '5',
- 'localunit_id' => '5',
- 'name' => 'Transport',
- 'parent_id' => '0',
- 'id_shop' => '-1',
- 'deleted' => '0',
- 'parent' => '#',
- 'group' => 1,
- )),
- 3 =>
- stdClass::__set_state(array(
- 'unit_id' => '7',
- 'localunit_id' => '7',
- 'name' => 'm',
- 'parent_id' => '19',
- 'id_shop' => '-1',
- 'deleted' => '0',
- 'parent' => '19',
- 'group' => 1,
- )),
- 4 =>
- stdClass::__set_state(array(
- 'unit_id' => '19',
- 'localunit_id' => '8',
- 'name' => 'Top',
- 'parent_id' => '0',
- 'id_shop' => '-1',
- 'deleted' => '0',
- 'parent' => '#',
- 'group' => 2,
- )),
- )
- private $testVar=[];
- function flatTree($elements)
- {
- $cnt=0;
- foreach($elements as $element)
- {
- $cnt++;
- if(isset($element->children)){
- $this->flatTree($element->children);
- }
- $tempElement=$element;
- if(isset($tempElement->children))
- unset($tempElement->children);
- $tempElement->group=$cnt;
- $this->testVar[]=$tempElement;
- }
- return ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement