title: Remove last comma from foreach array result
body: <p>I have this small function that let's me update any table and any values that I submit via a form. This is for personal use and no security is needed. But I need to remove the last comma from the script. First, here is the code:</p>
  
  <pre><code>public function updateForm($table, $formValues, $formID)
  {
      foreach ($formValues as $key =&gt; $val)
      {
          $form = "$key = '$val', ";
          $this-&gt;mysqli-&gt;query("UPDATE `$table` SET $form WHERE id = '$formID'");
      }
  }
  </code></pre>
  
  <p>If I submit 3 fields called <code>field1</code>, <code>field2</code>, and <code>field3</code> which contain the values <code>test1</code>, <code>test2</code> and <code>test3</code>, the <code>$form</code> will look like this:</p>
  
  <blockquote>
    <p>field1 = 'test1', field2 = 'test2', field3 = 'test3',</p>
  </blockquote>
  
  <p>But that last comma needs to be gone. How would I accomplish this? I have tried everything I can think of, including <code>rtrim($form,',');</code> - But this also does not remove the last comma from the populated values.</p>
  
  <p>Any shove into the right direction would be greatly appreciated :)</p>