fork download
  1. <?php
  2.  
  3. $in = [1, 2, 3, 4, 5, 6];
  4.  
  5. $chunks = array_chunk($in, 3);
  6.  
  7. $result = array_map(foo, $chunks);
  8.  
  9. print_r($result);
  10.  
  11. function foo($chunk) {
  12. $chunk = array_combine(['a', 'b', 'c'], $chunk);
  13. $chunk['s'] = ($chunk['a'] + $chunk['b']) * $chunk['c'] / 2;
  14. return $chunk;
  15. };
  16.  
  17.  
  18.  
Success #stdin #stdout #stderr 0s 82560KB
stdin
Standard input is empty
stdout
Array
(
    [0] => Array
        (
            [a] => 1
            [b] => 2
            [c] => 3
            [s] => 4.5
        )

    [1] => Array
        (
            [a] => 4
            [b] => 5
            [c] => 6
            [s] => 27
        )

)
stderr
PHP Notice:  Use of undefined constant foo - assumed 'foo' in /home/v2M9f0/prog.php on line 7