title: Run Inner Loop after each 3rd iteration of outer loop
body: <p>I have 2 loops Inner Loop &amp; Outer Loop.</p>
  
  <p>When Outer loops reaches its third iteration, then inner loop should run. and i do like this.</p>
  
  <pre><code> &lt;?php 
         foreach($this-&gt;posts as $post){ 
   ?&gt;
             &lt;div id="post"&gt;
             &lt;/div&gt;
            &lt;?php  
                   foreach($this-&gt;domain_ads as $ads) { 
                        if($i%3==0){ 
             ?&gt;
                             &lt;div id="ads"&gt;
                             &lt;/div&gt;
            &lt;?php       }
                   } ?&gt;
   &lt;?php 
        }
   ?&gt;
  </code></pre>
  
  <p>And the Results are like this</p>
  
  <p><a href="https://i.stack.imgur.com/Lywd5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Lywd5.png" alt="enter image description here"></a></p>
  
  <p><strong>Problem:</strong></p>
  
  <p>The problem is that inner loop shows all results after 3rd iteration. But i want to show only one result of inner loop, and then second result of inner loop should show after next 3 iterations of outer loop. </p>
  
  <p>How can i solve this problem ?</p>