title: Foreach to add Specific Products to an Array
body: <p>I had a previous problem which I have somewhat overcome. However this has resulted in a new problem which when fixed it should be working as intended.  </p>
  
  <p>I have created an <code>array</code> of <strong>Orders</strong> from a csv file and have managed to extract the data from the <strong>Orders (Products, Address etc.)</strong> and be printed together (Which was originally first problem). For example the csv file contains <strong>2 Orders</strong> which prints them all together such as:</p>
  
  <pre><code>Order: Order1
  Recipient: Timmy
  Address: 123 Street
  Products:
  Table (Quantity: 1)
  Cup (Quantity 4)
  
  Order: Order2
  Recipient: Billy
  Address: 456 Street
  Products:
  Chair (Quantity 5)
  </code></pre>
  
  <p>The new problem is now this data needs to go back into multiple <code>arrays</code> because of the API which is being used. I have this nearly working apart from the products, which is currently adding products from the previous order. Using the above example, the <code>array</code> would be the following:</p>
  
  <pre><code>//Order1
  array(2)
  {
      [0]=&gt; array(7)
      {
          ["Product"]=&gt; string(13) "Table"
          ["Quantity"]=&gt; float(1)
      } 
  
      [1]=&gt; array(7)
      {
          ["Product"]=&gt; string(13) "Cup"
          ["Quantity"]=&gt; float(4)
      }
  }
  
  //Order2
  array(3)
  {
      [0]=&gt; array(7)
      {
          ["Product"]=&gt; string(13) "Table"
          ["Quantity"]=&gt; float(1)
      } 
  
      [1]=&gt; array(7)
      {
          ["Product"]=&gt; string(13) "Cup"
          ["Quantity"]=&gt; float(4)
      }
  
  [2]=&gt; array(7)
      {
          ["Product"]=&gt; string(13) "Chair"
          ["Quantity"]=&gt; float(5)
      }
  } 
  </code></pre>
  
  <p>As shown above, the products from the previous order is duplicated onto the second order. The other order details are working as intended and being inserted as separate records into the database (Order Number, Address etc.). I'm unsure where I am going wrong, but this is the part of the code for the products <code>array</code>:</p>
  
  <pre><code>    foreach ($Order[$OrderNumber][$RecipientName][$Address1] as $key =&gt; $value)
      {   
          $APIOrderItem[] = array('Product' =&gt; $key,
                                  'Quantity' =&gt; $value);
      }
  
  $Items = array('APIOrderItem' =&gt; $APIOrderItem);
  </code></pre>
  
  <p>If previous code is required, I'll happily edit this post.</p>