title: PHP push objects to array from foreach loop
body: <p>I have set up a post CURL request where I'm receiving data from the front end and then formatting it a format which another third-party API can receive.</p>
  <p>I'm struggling with how I can add some dynamic product data to the main array list via a foreach loop, as it's a post request it's fairly hard to debug, I just get a cors error back on the front end.</p>
  <pre><code>$data = array(
          'TradingName'=&gt;'Olivias',
          'OrderNumber'=&gt;$_POST['OrderNumber'],
          'OrderReference'=&gt;$_POST['OrderReference'],
          'Recipient'=&gt;$_POST['Recipient'],
          'Address'=&gt;$_POST['Address'],
          'Postcode'=&gt;$_POST['Postcode'],
          'ContactHome'=&gt;$_POST['ContactHome'],
          'ContactWork'=&gt;$_POST['ContactWork'],
          'ContactMobile'=&gt;$_POST['ContactMobile'],
          'ContactEmail'=&gt;$_POST['ContactEmail'],
          'Charge'=&gt;$_POST['Charge'],
          'DeliveryInstructions'=&gt;$_POST['DeliveryInstructions'],
          'OtherInstructions'=&gt;$_POST['OtherInstructions'],
          'TimedService'=&gt;$_POST['TimedService'],
          'ServiceType'=&gt;$_POST['ServiceType'],
          'ServiceLevel'=&gt;$_POST['ServiceLevel'],
          'DeliveryPoint'=&gt;$_POST['DeliveryPoint'],
          'UnpackItems'=&gt;$_POST['UnpackItems'],
          'TakePackagingAway'=&gt;$_POST['TakePackagingAway'],
          'Assemble'=&gt;$_POST['Assemble'],
          'Disassemble'=&gt;$_POST['Disassemble'],
          'CollectDisposal'=&gt;$_POST['CollectDisposal'],       
      );
      
  
      
      foreach($_POST['fulfillmentItems'] as $i =&gt; $item){
              array_push($data, (object)[
                  'Action_'.$i+1=&gt;,'Deliver',
                  'QTY_'.$i+1=&gt;1,
                  'Code_'.$i+1=&gt;$item[$i]['sku'],
                  'Description_'.$i+1=&gt;$item[$i]['description'],
                  'Parts_'.$i+1=&gt;1,
                  'Weight_'.$i+1=&gt;$item[$i]['weight'],
                  'Cube_'.$i+1=&gt;1,
              ]);
          }
  </code></pre>
  <p>I'm just trying to add that bottom list to the top one, e.g Action_1 ...... Action_2...</p>
  <p>Here's an example :-</p>
  <pre><code>'Recipient'=&gt;'Joe Smith',
  'Address'=&gt;'2 Paramo House, Darlington',
  'Postcode'=&gt;'DL3 0LP',
  'ContactHome'=&gt;'',
  'ContactWork'=&gt;'01325 952050',
  'ContactMobile'=&gt;'',
  'ContactEmail'=&gt;'support@gsit.co.uk',
  'Charge'=&gt;32.50,
  'DeliveryInstructions'=&gt;'Leave in Porch',
  'OtherInstructions'=&gt;'Customer hard of hearing',
  'TimedService'=&gt;'All Day',
  'ServiceType'=&gt;'Standard',
  'ServiceLevel'=&gt;'2 Man',
  'DeliveryPoint'=&gt;'Room Of Choice',
  'UnpackItems'=&gt;'',
  'TakePackagingAway'=&gt;'',
  'Assemble'=&gt;'',
  'Disassemble'=&gt;'',
  'CollectDisposal'=&gt;'',
  'Action_1'=&gt;'Deliver',
  'QTY_1'=&gt;1,
  'Code_1'=&gt;'HG00023',
  'Description_1'=&gt;'Silver Birch Bed Frame',
  'Parts_1'=&gt;3,
  'Weight_1'=&gt;23,
  'Cube_1'=&gt;1,
  'Action_2'=&gt;'Collect',
  'QTY_2'=&gt;1,
  'Code_2'=&gt;'HG00023',
  'Description_2'=&gt;'Silver Birch Bed Frame (damaged)',
  'Parts_2'=&gt;3,
  'Weight_2'=&gt;23,
  'Cube_2'=&gt;1     
  </code></pre>