title: foreach in symfony 2
body: <p>Having trouble working out how to get the last iterate row every 4 it puts in a  but i need to find the last one so I can make that do something </p>
  
  <pre><code>foreach( $gallery-&gt;getMedia() as $key =&gt; $media )
  {
          if( ($key % 4 ) == 0 ) $html .= '&lt;div class="clear"&gt;&lt;/div&gt;';
          $url = $media-&gt;dir . '/' . $media-&gt;filename;
  
          $html .= sprintf( '&lt;li&gt;&lt;a href="#photo-%s" class="album_image_wrapper" id="photo_%s" title="%s" alt="%s" target="_blank" class="image-link" rel="slideshow"&gt;&lt;div style="background-image: url(\'',
                  $media-&gt;id ,
                  $media-&gt;id ,
                  $url,
                  $gallery-&gt;name ,
                  $media-&gt;id ,
                  $this-&gt;generateThumbUrl( $url, array( 'width' =&gt; 100, 'height'=&gt; 120, 'zoom' =&gt; true) ),
                  $media-&gt;title,
                  $galleryID  );
  </code></pre>