fork(1) download
  1. <?php
  2.  
  3. $data = [1, 2, 3, 4, 5, 10, 20, 30, 40, 50, 0, 0, 0, 100];
  4. $data = [19, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31];
  5.  
  6. $result = [];
  7.  
  8. foreach($data as $n => $value) {
  9. $n = ($n % 6) + 1;
  10. $result["amount$n"] += $value;
  11. }
  12.  
  13. var_export($result);
Success #stdin #stdout #stderr 0.01s 82560KB
stdin
Standard input is empty
stdout
array (
  'amount1' => 45,
  'amount2' => 48,
  'amount3' => 50,
  'amount4' => 52,
  'amount5' => 54,
  'amount6' => 56,
)
stderr
PHP Notice:  Undefined index: amount1 in /home/vA8q3U/prog.php on line 10
PHP Notice:  Undefined index: amount2 in /home/vA8q3U/prog.php on line 10
PHP Notice:  Undefined index: amount3 in /home/vA8q3U/prog.php on line 10
PHP Notice:  Undefined index: amount4 in /home/vA8q3U/prog.php on line 10
PHP Notice:  Undefined index: amount5 in /home/vA8q3U/prog.php on line 10
PHP Notice:  Undefined index: amount6 in /home/vA8q3U/prog.php on line 10