Views group different number of divs of a view by wrapping them
Here is what worked for me. Mind that I only got it to work in an unformatted list format in views.

&lt;?php
  $currIx = 1; // This will be our incremental index variable. Let's make it 1-based to maintin consistency with your example.
  $currWrapperIx = 1; // Wrapper counter
  $wasOpen = FALSE; // This variable will be used later as a flag to watch for properly closing wrapper divs.
?&gt;

&lt;?php if (!empty($title)): ?&gt;
  &lt;p class="&lt;?php print $title ?&gt;"&gt;&lt;?php print $title; ?&gt;&lt;/p&gt;
&lt;?php endif; ?&gt;
&lt;?php foreach ($rows as $id =&gt; $row): ?&gt;
  &lt;?php switch ($currIx){
    // List the row indices that are supposed to begin a new wrapper.
    case 1:
    case 27:
      if($wasOpen == TRUE){ // Close current wrapper div before opening a new one.
        print "&lt;/div&gt;\n";
        $wasOpen = FALSE;
        $currWrapperIx ++; // Increment the index for next wrapper's class.
      }
      // Open a new wrapper div
      print "&lt;div class=\"wrapper-{$currWrapperIx}\"&gt;\n";
      $wasOpen = TRUE;
      break;

    default:
      // For other row indices do nothing.
    }
  ?&gt;
&lt;!--&lt;div &lt;?php if ($classes_array[$id]) { print 'class="' . $classes_array[$id] .'"';  } ?&gt;&gt;--&gt;
  &lt;div class="&lt;?php print $id ?&gt;"&gt;&lt;?php print $row; ?&gt;&lt;/div&gt;
&lt;!-- &lt;/div&gt;--&gt;

  &lt;?php $currIx ++; ?&gt;
&lt;?php endforeach; ?&gt;

&lt;?php
    // Close the last wrapper.
    if($wasOpen == TRUE){
      print "&lt;/div&gt;\n";
      $wasOpen = FALSE;
    }
?&gt;


Kudos go out to @Artur. Great support. Many thanks.