fork download
  1. <?php
  2.  
  3. $cases = array(23, 18, 5, 8, 10, 16);
  4. $totals = array();
  5. array_walk($cases, function($v) use (&$totals) { $totals[] = end($totals) + $v;});
  6.  
  7. print_r($totals);
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
Array
(
    [0] => 23
    [1] => 41
    [2] => 46
    [3] => 54
    [4] => 64
    [5] => 80
)