title: foreach loop result assign to progressing variable
body: <p>I have a form that includes 4 text fields and multiple file upload (5 files/fields):</p>
  
  <p>The database table has 9 fields, 4 for the text fields and the remaining 5 should hold a URL path to the images being uploaded by the form, for the 5 URL fields in the database they are simply named as image1, image2, image3…</p>
  
  <p>Normally we collect the form data and do whatever MySQL query we need to insert or update, but I cant figure out how to assign the <code>foreach</code> loop results to a progressive/dynamic variable name so that after the iterations I am only doing 1 MySQL query/insert.</p>
  
  <pre><code>$inum=0;
  
  foreach ($_FILES["prodi"]["error"] as $key =&gt; $error)
  {
      if ($error == UPLOAD_ERR_OK) {
          $tmp_name = $_FILES["prodi"]["tmp_name"][$key];
          $name = $_FILES["prodi"]["name"][$key];
          $type = $_FILES["prodi"] ["type"] [$key];
          if ($type=="image/jpg" OR $type=="image/jpeg" OR $type=="image/pjpeg" OR $type=="image/png")
          {move_uploaded_file($tmp_name, "../zzz/zzz-images/$name");
          $ipath=$domain."/zzz/zzz-images/".$name;
          $inum++;
          $i="image".$inum; // STUCK AT THIS POINT //}
  }
  </code></pre>
  
  <p>So, if i were to echo <code>$i</code> and <code>$ipath</code> inside the loop, i will get:</p>
  
  <pre><code>image1 (The table field storing the url)  /  *ttp://www.whaterver......(the url stored)
  
  image2 (The table field storing the url)  /  *ttp://www.whaterver......(the url stored)
  </code></pre>
  
  <p>And so on until there are no more files in the array to process, but how do i set each loop result to a new variable so that the mysqli query works like this:</p>
  
  <pre><code>mysqli_query($con,"INSERT INTO `table1` (`field1`,`field2`,`field3`,`field4`,`image1`,`image2`,`image3`,`image4`,`image5`) VALUES ('field1',field2','field3','field4','loop_result1','loop_result2','loop_result3' etc. etc. etc.);")
  </code></pre>