title: How can I insert data into multiple columns using one query with a foreach loop?
body: <p>I have an associative array that inserts each 'key' and 'value' into my database table. At the moment an individual query runs for each key <strong><em>for each iteration</em></strong> of the loop, however I want it to grab each 'key' and 'element', and insert them as pairs in <strong><em>one</em></strong> query.</p>
  
  <p>PHP:</p>
  
  <pre><code>$elements = array(
      'column_1' =&gt; 'data1',
      'column_2' =&gt; 'data2',
      'column_3' =&gt; 'data3'
  );
  
  foreach($elements as $key=&gt;$value) {
      $key = $key;
      $value = $value;
  
      DB::query('INSERT INTO `table` (' . $key . ') VALUES (?);', array($value));
  }
  </code></pre>