<p>How do I multiply the values of a multi-dimensional array with weights and sum up the results into a new array in PHP or in general?</p>

<p>The boring way looks like this:</p>

<pre><code>$weights = array(0.25, 0.4, 0.2, 0.15);
$values  = array
           ( 
             array(5,10,15), 
             array(20,25,30), 
             array(35,40,45), 
             array(50,55,60)
           );
$result  = array();

for($i = 0; $i &lt; count($values[0]); ++$i) {
  $result[$i] = 0;
  foreach($weights as $index =&gt; $thisWeight)
    $result[$i] += $thisWeight * $values[$index][$i];
}
</code></pre>

<p>Is there a more elegant solution?</p>

Hm...
```
```
foreach($values as $index => $ary )
  $result[$index] = array_sum($ary) * $weights[$index];
```
```