title: PHP count sum of several columns based on array
body: <p>I want to sum some columns together based on a array. Previous I did it like this:</p>
  
  <pre><code>$data = $db-&gt;query("SELECT idnummer, productnaam,($kolommen[0]+$kolommen[1]+$kolommen[2]+$kolommen[3]+$kolommen[4]+$kolommen[5]+$kolommen[6]+$k
  olommen[7]+$kolommen[8]+$kolommen[9]+$kolommen[10]+$kolommen[11]+$kolommen[12]+$kolommen[13]+$
  kolommen[14]) AS total FROM wasmachine ORDER BY total DESC, prijs LIMIT 0, 5") or 
  trigger_error("Fout in de query");
  </code></pre>
  
  <p>But I think this is not the right way to do it, because I want it dynamically. I want to use the full array like</p>
  
  <pre><code>$data = $db-&gt;query("SELECT idnummer, productnaam,($kolommen) AS total FROM wasmachine ORDER BY total DESC, prijs LIMIT 0, 5") or 
  trigger_error("Fout in de query");
  </code></pre>
  
  <p>This is my database example:</p>
  
  <pre><code>idnummer | productnaam | v1a2 | v2a1 | v3a2
  1        |  test 1     |   1  |   2  |   1
  2        |  test 2     |   1  |   2  |   1
  3        |  test 3     |   1  |   2  |   1
  4        |  test 4     |   1  |   2  |   1
  </code></pre>
  
  <p>I tried it with <strong>array_sum</strong> and <strong>count</strong> but I can't figure it out.</p>
  
  <p>Thanks for helping me!</p>