title: how to pass a foreach loop into an API payload - using CI
body: <p>i have a dynamically generated upload form , the name values are based on the API
  i am expected to pass all these values back to another api</p>
  <ol>
  <li>the link to uploaded file</li>
  <li>Description</li>
  <li>Serial key</li>
  </ol>
  <p>these values to be posted are best retrieved via a for each loop</p>
  <p>my question is how to pass the values from a foreach loop into a payload or if there is something i need to do as i am new into programming
  <a href="https://i.stack.imgur.com/bO71a.png" rel="nofollow noreferrer">front end of dynamically generated form</a></p>
  <p>API CODE</p>
  <pre><code>public function post_Loan(){ 
       $ProductCode=$this-&gt;input-&gt;post('productcode');
       $loantype=$this-&gt;input-&gt;post('loantype');
       $Amount = $this-&gt;input-&gt;post('Amount');
       $Instalment= $this-&gt;input-&gt;post('Instalment');
       $bankaccno = $this-&gt;input-&gt;post('bankaccno');
       $bankname = $this-&gt;input-&gt;post('bankname');
       $loanpurpose = $this-&gt;input-&gt;post('loanpurpose');
       $repay =  $this-&gt;input-&gt;post('repay');
      
     // looped uploaded doc based on product code selected 
      if (!empty($_POST[&quot;productcode&quot;])) {
         $Loandoucuments = $this-&gt;Gemini_model-&gt;get_loandocument($_POST[&quot;productcode&quot;]);
         $config['upload_path'] ='./images/';
         $config['allowed_types'] = '*';
         $config['max_size'] = 2000;
         $config['max_width'] = 1500;
         $config['max_height'] = 1500;
       // $config['encrypt_name'] = TRUE;
         $this-&gt;upload-&gt;initialize($config);
         foreach($Loandoucuments as $doc){
         if (!$this-&gt;upload-&gt;do_upload($doc['SerialKey'])) {
           } else {
                  $data = $this-&gt;upload-&gt;data();
                  //description , serial key and link to uploaded file 
                $doc['Description']; //Description 
                 $doc['SerialKey']; // SerialKey
                 anchor('images/'.$data['file_name']) ; //UploadLink
            }
        } 
      }else{ }
  
      
   
      $url = &quot;http://demo.geminiapp.net/service/Request.svc/api/loanrequest&quot;;
  
  
       $data = [
  
  
          
  
   &quot;Amount&quot;=&gt;$Amount,
   &quot;BankAccountNo&quot;=&gt;$bankaccno,
   &quot;BankCode&quot;=&gt;$bankname,
   &quot;ContractType&quot;=&gt;$loantype, 
   &quot;CurrencyCode&quot;=&gt;$currency,
   &quot;CustomerID&quot;=&gt;&quot;3&quot;,
   &quot;Document&quot;=&gt;[
     &quot;ContractDocs&quot;=&gt;[
     &quot;Description&quot;=&gt; //$doc['Description'],
     &quot;SerialKey&quot;=&gt;//$doc['SerialKey'],
     &quot;UploadLink&quot;=&gt;//$Link to be uploaded '
     ]
   ],
   &quot;Installment&quot;=&gt;$Instalment,
   &quot;LNAccountNo&quot;=&gt;&quot;00&quot;,//$AccountNo,
   &quot;ProductCode&quot;=&gt;$ProductCode,
   &quot;PurposeKey&quot;=&gt;$loanpurpose,
   &quot;RepayKey&quot;=&gt;$repay
  
    
  
   
   ];
  
  
   
   $curl = curl_init($url);
   curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
   curl_setopt($curl, CURLOPT_POST, true);
   curl_setopt($curl, CURLOPT_POSTFIELDS,  json_encode($data));
   curl_setopt($curl, CURLOPT_HTTPHEADER, [
         'Authorization: Bearer yP5lnti7wDChJxwmBYz7dpbgbzGqQRG1dyvAZihesrA=',
         'Content-Type: application/json'
       ]);   
         $response = curl_exec($curl);
       curl_close($curl);
       $result = json_decode($response);
       print_r($result);
  
  
   
   }//post loan
  </code></pre>