code: 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,
      ];
    }
docs: Export group to an object
  
  @return   object