title: Using an IF statement within a FOREACH loop in PHP
body: <p>I'm trying to execute the following code but it's not working:</p>
  
  <pre><code>&lt;?php foreach($reciepts as $value) { 
      $extension = get_file_extension($value);
      if($extension == "pdf") { ?&gt;
          &lt;p&gt;Receipt:&lt;/p&gt;&lt;br&gt;&lt;embed src="&lt;?php echo $value; ?&gt;"&gt;
      &lt;?php }
      else { ?&gt;
          &lt;p&gt;Receipt:&lt;/p&gt;&lt;br&gt;&lt;img style="max-width:500px; max-height:500px;" src="&lt;?php echo $value; ?&gt;" /&gt;
      &lt;?php } ?&gt;
  </code></pre>
  
  <p>The <code>$reciepts</code> array iin this case is:</p>
  
  <pre><code>[7] =&gt; Array
              (
                  [0] =&gt; http://coppermountain.co.uk/wp-content/uploads/gravity_forms/12-c07945f2e8e37e124bd5be2c8a979300/2016/02/Screen-Shot-2016-02-01-at-09.33.18.png
                  [1] =&gt; http://coppermountain.co.uk/wp-content/uploads/gravity_forms/12-c07945f2e8e37e124bd5be2c8a979300/2016/02/Expenses-1.pdf
              )
  </code></pre>
  
  <p>The function to get the file extension:</p>
  
  <pre><code>function get_file_extension($value) {
      return substr(strrchr($value,'.'),1);
  }
  </code></pre>
  
  <p>The tests I have run so far:</p>
  
  <pre><code>$extension = $form_data['field'][7][1];
  echo get_file_extension($extension);
  </code></pre>
  
  <p><code>$extension</code> echoes out <code>pdf</code> as expected</p>
  
  <p>Also the loop works fine if I don't include the IF/ELSE statement as below:</p>
  
  <pre><code>&lt;?php foreach($reciepts as $value) { ?&gt;
      &lt;p&gt;Receipt:&lt;/p&gt;&lt;br&gt;&lt;img style="max-width:500px; max-height:500px;" src="&lt;?php echo $value; ?&gt;" /&gt; 
  &lt;?php } ?&gt;
  </code></pre>
  
  <p>Thanks</p>