title: PHP: How do you determine every Nth iteration of a loop?
body: <p>I wanted to echo an image every after 3 post via XML here is my code :</p>
  
  <pre><code>&lt;?php
  // URL of the XML feed.
  $feed = 'test.xml';
  // How many items do we want to display?
  //$display = 3;
  // Check our XML file exists
  if(!file_exists($feed)) {
    die('The XML file could not be found!');
  }
  // First, open the XML file.
  $xml = simplexml_load_file($feed);
  // Set the counter for counting how many items we've displayed.
  $counter = 0;
  // Start the loop to display each item.
  foreach($xml-&gt;post as $post) {
    echo ' 
    &lt;div style="float:left; width: 180px; margin-top:20px; margin-bottom:10px;"&gt;
   image file&lt;/a&gt; &lt;div class="design-sample-txt"&gt;'. $post-&gt;author.'&lt;/div&gt;&lt;/div&gt;
  ';
  
    // Increase the counter by one.
    $counter++;
    // Check to display all the items we want to.
    if($counter &gt;= 3) {
      echo 'image file';
      }
    //if($counter == $display) {
      // Yes. End the loop.
     // break;
    //}
    // No. Continue.
  }
  ?&gt;
  </code></pre>
  
  <p>here is a sample first 3 are correct but now it doesn't loop idgc.ca/web-design-samples-testing.php</p>