Use foreach loop with counter
<p>I want to output the results of a foreach statement but I want them grouped into a div in 3's</p>

<p>So like:</p>

<pre><code>&lt;div&gt;image image image&lt;/div&gt;
&lt;div&gt;image image image&lt;/div&gt;
&lt;div&gt;image image image&lt;/div&gt;
</code></pre>

<p>Here is my code so far:</p>

<pre><code>$args = array( 'numberposts' =&gt; 3, 'offset'=&gt; 0, 'category' =&gt; 9 );

            $myrows = get_posts($args);
                foreach($myrows as $row) {  ?&gt;
                &lt;div&gt;
                    &lt;?php if ( has_post_thumbnail($row-&gt;ID)) {
                    echo '&lt;a href="' . get_permalink( $row-&gt;ID ) . '" title="' . esc_attr($row-&gt;post_title ) . '"&gt;';
                        echo get_the_post_thumbnail($row-&gt;ID);
                    echo '&lt;/a&gt;';
                    }?&gt;
                &lt;/div&gt;
                &lt;?php } ?&gt;
</code></pre>
