title: PHP coding problem to get multiple instances from an array based on quantity variable within
body: <p>I'm not sure if anyone can help me with a problem I have..</p>
  
  <p>I have a parse function that includes the code:</p>
  
  <pre><code>foreach ($values as $element) {
  
  $nodeName = $element["tag"];
  
  switch ($element['type']) {
  
  case 'open':
  
  if ($nodeName == "SHOPPINGLIST") {
  $this-&gt;publicationID = $element["attributes"]["PUBLICATIONID"]; 
  }
  
  if ($nodeName == "ENTRY") {
  
  $entry = new ShoppingCartEntry();
  $entry-&gt;quantity = $element["attributes"]["QUANTITY"];
  
  }
  
  if ($nodeName == "ITEM") {
  
  $entry-&gt;productID = $element["attributes"]["PRODUCTID"];
  $entry-&gt;price = $element["attributes"]["PRICE"];
  
  array_push($this-&gt;entries, $entry);
  }   
  
  break;
  
  case 'complete':
  
  if ($nodeName == "NAME") {
  $entry-&gt;name = $element["value"];
  }
  
  if ($nodeName == "DESCRIPTION") {
  $entry-&gt;description = $element["value"];
  }   
  
  break;
  
  }
  }
  </code></pre>
  
  <p>As a result I have an array in the format of:</p>
  
  <pre><code>Array ( 
  [0] =&gt; ShoppingCartEntry Object ( 
  [quantity] =&gt; 3 
  [productID] =&gt; 00001 
  [price] =&gt; 4.99 
  [name] =&gt; Full English 
  [description] =&gt; Eggs, Beans, Sheesh Kebab Served with Toast ) 
  </code></pre>
  
  <p>At the minute I am printing the item entries using:</p>
  
  <pre><code>foreach ($entries as $entry) { 
  }
  </code></pre>
  
  <p>However now I need an entry to be created for each quantity value there is of a product. So if the quantity of the product in the entry is 3, Then either an alteration needs to be made so that 3 entries are created or even if there is someway of editing the foreach loop, so that it loops for "$quantity" amount of times..</p>
  
  <p>Any pointers in the right direction would be appreciated.</p>
  
  <p>Thanks</p>