src/TreeGroup.php
public function toObject()
  {
    $groups = $this->groups;
    foreach($groups as &$group){
      $group = $group->toObject();
    }
    
    $items = $this->items;
    foreach($items as &$item){
      $item = $item->toObject();
    }
    
    return (object)[
      'type'   => $this->type, 
      'value'  => $this->value, 
      'text'   => $this->text, 
      'groups' => $groups,
      'items'  => $items,
    ];
  }
public function toObject()
  {
    $groups = $this->groups;
    foreach($groups as &$group){
      $group = $group->toObject();
    }
    
    $items = $this->items;
    foreach($items as &$item){
      $item = $item->toObject();
    }
    
    return (object)[
      'type'   => $this->type, 
      'value'  => $this->value, 
      'text'   => $this->text, 
      'groups' => $groups,
      'items'  => $items,
    ];
  }
Export group to an object

@return   object