title: php foreach generating trash
body: <p>I have here a quite complicated loop what I would like to modify while is not really working as I expected. The problem is: my if statements else condition is generating trash and I don't really know where the problem comes</p>
  
  <p><img src="https://i.stack.imgur.com/xgQLi.jpg" alt="enter image description here"></p>
  
  <pre><code>&lt;div id="container"&gt;
      &lt;?php include 'header.php';
      foreach ($vars as $item):
  
  
  
      if (is_array($item['productItems'])):?&gt;
  
      &lt;div class="product_box"&gt;
          &lt;h4&gt;
              &lt;?php echo $item['title']?&gt;
          &lt;/h4&gt;
  
          &lt;?php foreach($item['productItems'] as $products):?&gt;
  
          &lt;?php foreach($products as $key=&gt;$product):?&gt;
  
  
          &lt;div class="product"&gt;
  
              &lt;div class="image_holder"&gt;
  
                  &lt;a href="&lt;?php echo $product['image']['medium'];?&gt;" class="preview"&gt;
                      &lt;img src="&lt;?php echo $product['image']['small'];?&gt;"
                      alt="gallery thumbnail" title="" /&gt;
                  &lt;/a&gt;
  
  
                  &lt;?php foreach($product['trackingLinks'] as $key=&gt;$trackinglink): ?&gt;
                  &lt;a href="&lt;?php echo $trackinglink[0]['ppc']?&gt;"&gt; &lt;span&gt;&lt;?php echo $product['name'];?&gt;
                  &lt;/span&gt;
                  &lt;/a&gt;
              &lt;/div&gt;
  
              &lt;h5&gt;
                  &lt;?php echo 'Preise:&amp;nbsp;'. $product['price'].' &amp;nbsp;'.$product['currency'];?&gt;
              &lt;/h5&gt;
              &lt;span&gt;&lt;?php echo 'Versand Kosten:&amp;nbsp;'.$product['shippingCosts'].'&amp;nbsp;EUR';?&gt;
              &lt;/span&gt;
              &lt;p&gt;
                  &lt;?php echo (substr($product['descriptionLong'], 0,150 )).'&lt;a href="'.$trackinglink[0]['ppc'].'"&gt;...mehr&lt;/a&gt;';?&gt;
              &lt;/p&gt;
              &lt;a class="shopping_button"
                  href="&lt;?php echo $trackinglink[0]['ppc']?&gt;"&gt;zum Shop&lt;/a&gt;
  
  
  
          &lt;/div&gt;
  &lt;?php endforeach ?&gt;
          &lt;?php endforeach ?&gt;
                  &lt;?php endforeach ?&gt;
  
          &lt;div class="ajax_bar"&gt;
  
              &lt;select id="ajax_call" size="1" name="Weitere Produkte"&gt;
                  &lt;option value='50'&gt;Weitere Produkte&lt;/option&gt;
                  &lt;option value='100'&gt;weitere 100&lt;/option&gt;
                  &lt;option value='150'&gt;weitere 150&lt;/option&gt;
              &lt;/select&gt;
  
          &lt;/div&gt;
  
      &lt;/div&gt;
  
      &lt;?php else: ?&gt;
  
  
      &lt;div class="text_box"&gt;
          &lt;h2&gt;
              &lt;?php echo $item['title'];?&gt;
          &lt;/h2&gt;
          &lt;p&gt;
              &lt;?php echo $item['text'];?&gt;
          &lt;/p&gt;
  
  
      &lt;/div&gt;
          &lt;?php endif; ?&gt;
              &lt;?php endforeach; ?&gt;
  
  
  &lt;?php include 'footer.php';?&gt;
  
  &lt;/div&gt;
  </code></pre>