title: PHP Foreach loop if field is not empty
body: <p>I am trying to master the art of the foreach loop; I have the following code which I am using with WordPress and the Advanced Custom Fields pluging. I want to turn it into a foreach loop.</p>
  
  <pre><code>&lt;li data-thumb="&lt;?php the_field('image_1'); ?&gt;"&gt; 
      &lt;img src="&lt;?php the_field('image_1'); ?&gt;" /&gt;
  &lt;/li&gt;
  &lt;li data-thumb="&lt;?php the_field('image_2'); ?&gt;"&gt; 
      &lt;img src="&lt;?php the_field('image_2'); ?&gt;" /&gt;
  &lt;/li&gt;
  &lt;li data-thumb="&lt;?php the_field('image_3'); ?&gt;"&gt; 
      &lt;img src="&lt;?php the_field('image_3'); ?&gt;" /&gt;
  &lt;/li&gt;
  &lt;li data-thumb="&lt;?php the_field('image_4'); ?&gt;"&gt; 
      &lt;img src="&lt;?php the_field('image_4'); ?&gt;" /&gt;
  &lt;/li&gt;
  &lt;li data-thumb="&lt;?php the_field('image_5'); ?&gt;"&gt; 
      &lt;img src="&lt;?php the_field('image_5'); ?&gt;" /&gt;
  &lt;/li&gt; 
  </code></pre>
  
  <p>I have tried writing the code below but it doesn't work, and I don't know how to limit the loop to 5 (images). Note that get_field returns the image url whilst the_field returns the image.</p>
  
  <pre><code>&lt;?php                       
  
      $i=1;
      foreach (!empty (get_field('property_image.$i.')) ) {
  
      print (' &lt;li data-thumb="&lt;?php the_field('property_image'.$i.'); ?&gt;"&gt; 
               &lt;img src="&lt;?php the_field('property_image'.$i.'); ?&gt; "&gt; 
               &lt;/li&gt; ');
  
      $i++; 
  
          }
  
  ?&gt;
  </code></pre>