title: Displaying array in a table by the type of each element
body: <p>I have an array that looks like this,but with much more elements:</p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [product_name] =&gt; Pizza Craft
              [dependency] =&gt; 0
              [product_type] =&gt; 1
              [quantity] =&gt; 1
          )
  )
  </code></pre>
  
  <p>In this array I have the products for a specif menu (the menu is different every day). The menu will be structured on 5 products type: main dish, trimmings, salad, soup, desert (in array, product_type from 1-5).</p>
  
  <p>I want to display this in a table,structured on products types, from the main dish to the desert. I did this and it's working, but I want to know if it's a better way because I have too many foreach.
  I'm using <code>unset($products[$key]);</code> after each <code>echo</code> for greater efficiency. This way, after I'm done with a product, I will remove it so the next foreach will not read previous products.
  So, how can I display this more efficiently?</p>
  
  <p>Note: I have a second array that's equal with the array from the db, so if I need to loop again, for some reason, throw the array, I will not do another request to the db.</p>
  
  <p>Display Code:</p>
  
  <pre><code>&lt;table&gt;
              &lt;tr&gt;
                  &lt;td&gt;Felul principal:&lt;/td&gt;
                  &lt;?php foreach($products as $key=&gt;$product):?&gt;
                      &lt;?php if($product['product_type'] == 1):?&gt;
                          &lt;td&gt;&lt;?php echo $product['product_name'];?&gt;&lt;/td&gt;
                          &lt;?php unset($products[$key]);?&gt;
                      &lt;?php endif;?&gt;
                  &lt;?php endforeach;?&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;Garnitura:&lt;/td&gt;
                  &lt;?php foreach($products as $key=&gt;$product):?&gt;
                      &lt;?php if($product['product_type'] == 2):?&gt;
                          &lt;td&gt;&lt;?php echo $product['product_name'];?&gt;&lt;/td&gt;
                          &lt;?php unset($products[$key]);?&gt;
                      &lt;?php endif;?&gt;
                  &lt;?php endforeach;?&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;Salata:&lt;/td&gt;
                  &lt;?php foreach($products as $key=&gt;$product):?&gt;
                      &lt;?php if($product['product_type'] == 3):?&gt;
                          &lt;td&gt;&lt;?php echo $product['product_name'];?&gt;&lt;/td&gt;
                          &lt;?php unset($products[$key]);?&gt;
                      &lt;?php endif;?&gt;
                  &lt;?php endforeach;?&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;Supa:&lt;/td&gt;
                  &lt;?php foreach($products as $key=&gt;$product):?&gt;
                      &lt;?php if($product['product_type'] == 4):?&gt;
                          &lt;td&gt;&lt;?php echo $product['product_name'];?&gt;&lt;/td&gt;
                          &lt;?php unset($products[$key]);?&gt;
                      &lt;?php endif;?&gt;
                  &lt;?php endforeach;?&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;Desert:&lt;/td&gt;
                  &lt;?php foreach($products as $key=&gt;$product):?&gt;
                      &lt;?php if($product['product_type'] == 5):?&gt;
                          &lt;td&gt;&lt;?php echo $product['product_name'];?&gt;&lt;/td&gt;
                          &lt;?php unset($products[$key]);?&gt;
                      &lt;?php endif;?&gt;
                  &lt;?php endforeach;?&gt;
              &lt;/tr&gt;
      &lt;/table&gt;
  </code></pre>