title: Output unique content at the end of my php foreach loop
body: <p>I have a foreach loop that outputs all the values for cells found in a Google Spreadsheet, wraps each value in a containing div and wraps a div around each row.</p>
  <p>Everything is working properly until I get to the final iteration of the loop where I am left with an open div at the end of the iterations.</p>
  <p>I know I need to add an elseIf statement that checks for the last iteration and outputs a closing div but I am lost as to how to accomplish this.</p>
  <p>Here is my code:</p>
  <pre><code>$response = $service-&gt;spreadsheets_values-&gt;get($spreadsheetId, $range);
  $values = $response-&gt;getValues();
  
  $ic = 0; /* ITEM count: iterates item count up for every cell pulled from the spreadsheet */
  
  $rc = 1; /* ROW count: iterates row count up for every row pulled from the spreadsheet */
  
  echo '&lt;div class=&quot;rowContainer&quot;&gt;';
  if (empty($values)) {
     print 'No data found.\n';
  } else {
      
     echo '&lt;div class=&quot;rowBreak rc'.$rc.'&quot;&gt;';
     $rc++;
     foreach ($values as $row) {
        for ($i = 0; $i &lt; sizeof($row); $i++) {
            echo '&lt;div class=&quot;item ic'.$ic.'&quot; id=&quot;ic'.$ic.'&quot;&gt;';
            echo $row[$i].'&lt;/div&gt;';
            $ic++;
            
            if ($ic % 13 == 0) { 
            echo '&lt;/div&gt;&lt;div class=&quot;rowBreak rc'.$rc.'&quot;&gt;'; $rc++;}
           
         /* Needs an else if here that echos just a closing div instead of the close / open divs */
            
        }
      
                                          
        }
        }
  echo '&lt;/div&gt;&lt;!-- .rowContainerEnd --&gt;';     
  
  </code></pre>
  <p>I believe I need something like the following but I do not know what to compare $rc to in my original code.</p>
  <pre><code>else if ($rc == ??SOMETHING?? - 1) {
          echo '&lt;/div&gt;';  
          $rc++;
      }
  </code></pre>