3v4l.org

run code in 300+ PHP versions simultaneously
<?php $estimate = array( array( 'gear' => 'MMG', 'total' => 315, 'efforts' => 9, 'afh' => 18 ), array( 'gear' => 'MMG', 'total' => 400, 'efforts' => 2, 'afh' => 6, ), array( 'gear' => 'BOO', 'total' => 200, 'efforts' => 20, 'afh' => 16, ), array( 'gear' => 'BOB', 'total' => 250, 'efforts' => 20, 'afh' => 16, ) ); $result = array_reduce($estimate, function($carry, $item) { if (!isset($carry[$item["gear"]])) { $carry[$item["gear"]] = $item; return $carry; } $carry[$item["gear"]]["total"] += $item["total"]; $carry[$item["gear"]]["efforts"] += $item["efforts"]; $carry[$item["gear"]]["afh"] += $item["afh"]; return $carry; }); print_r($result);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RHkpb
function name:  (null)
number of ops:  11
compiled vars:  !0 = $estimate, !1 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   29     1        INIT_FCALL                                               'array_reduce'
          2        SEND_VAR                                                 !0
          3        DECLARE_LAMBDA_FUNCTION                          ~3      [0]
   40     4        SEND_VAL                                                 ~3
   29     5        DO_ICALL                                         $4      
          6        ASSIGN                                                   !1, $4
   42     7        INIT_FCALL                                               'print_r'
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                                 
         10      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 10
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RHkpb
function name:  {closure}
number of ops:  27
compiled vars:  !0 = $carry, !1 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   30     2        FETCH_DIM_R                                      ~2      !1, 'gear'
          3        ISSET_ISEMPTY_DIM_OBJ                         0  ~3      !0, ~2
          4        BOOL_NOT                                         ~4      ~3
          5      > JMPZ                                                     ~4, ->10
   31     6    >   FETCH_DIM_R                                      ~5      !1, 'gear'
          7        ASSIGN_DIM                                               !0, ~5
          8        OP_DATA                                                  !1
   32     9      > RETURN                                                   !0
   35    10    >   FETCH_DIM_R                                      ~7      !1, 'gear'
         11        FETCH_DIM_R                                      ~10     !1, 'total'
         12        FETCH_DIM_RW                                     $8      !0, ~7
         13        ASSIGN_DIM_OP                +=               1          $8, 'total'
         14        OP_DATA                                                  ~10
   36    15        FETCH_DIM_R                                      ~11     !1, 'gear'
         16        FETCH_DIM_R                                      ~14     !1, 'efforts'
         17        FETCH_DIM_RW                                     $12     !0, ~11
         18        ASSIGN_DIM_OP                +=               1          $12, 'efforts'
         19        OP_DATA                                                  ~14
   37    20        FETCH_DIM_R                                      ~15     !1, 'gear'
         21        FETCH_DIM_R                                      ~18     !1, 'afh'
         22        FETCH_DIM_RW                                     $16     !0, ~15
         23        ASSIGN_DIM_OP                +=               1          $16, 'afh'
         24        OP_DATA                                                  ~18
   39    25      > RETURN                                                   !0
   40    26*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.12 ms | 1443 KiB | 15 Q