3v4l.org

run code in 300+ PHP versions simultaneously
<?php $res1 = [ ['ID' => 60,'TOTAL' => 500], ['ID' => 61,'TOTAL' => 600], ['ID' => 63,'TOTAL' => 500] ]; $res2 = [ ['ID' => 60,'TOTAL' => 600], ['ID' => 61,'TOTAL' => 700], ['ID' => 64,'TOTAL' => 800] ]; function summTotal(&$result, $parts) { array_walk($parts, function($item) use (&$result){ if (isset($result[$item['ID']])) { $result[$item['ID']]['TOTAL'] += $item['TOTAL']; } else { $result[$item['ID']] = $item; } }); } $result = []; summTotal($result, $res1); summTotal($result, $res2); print_r($result);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tC8Xu
function name:  (null)
number of ops:  15
compiled vars:  !0 = $res1, !1 = $res2, !2 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    7     1        ASSIGN                                                   !1, <array>
   23     2        ASSIGN                                                   !2, <array>
   25     3        INIT_FCALL                                               'summtotal'
          4        SEND_REF                                                 !2
          5        SEND_VAR                                                 !0
          6        DO_FCALL                                      0          
   26     7        INIT_FCALL                                               'summtotal'
          8        SEND_REF                                                 !2
          9        SEND_VAR                                                 !1
         10        DO_FCALL                                      0          
   28    11        INIT_FCALL                                               'print_r'
         12        SEND_VAR                                                 !2
         13        DO_ICALL                                                 
         14      > RETURN                                                   1

Function summtotal:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tC8Xu
function name:  summTotal
number of ops:  9
compiled vars:  !0 = $result, !1 = $parts
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   14     2        INIT_FCALL                                               'array_walk'
          3        SEND_REF                                                 !1
          4        DECLARE_LAMBDA_FUNCTION                          ~2      [0]
          5        BIND_LEXICAL                                             ~2, !0
   20     6        SEND_VAL                                                 ~2
   14     7        DO_ICALL                                                 
   21     8      > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 11
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tC8Xu
function name:  {closure}
number of ops:  15
compiled vars:  !0 = $item, !1 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   15     2        FETCH_DIM_R                                      ~2      !0, 'ID'
          3        ISSET_ISEMPTY_DIM_OBJ                         0          !1, ~2
          4      > JMPZ                                                     ~3, ->11
   16     5    >   FETCH_DIM_R                                      ~4      !0, 'ID'
          6        FETCH_DIM_R                                      ~7      !0, 'TOTAL'
          7        FETCH_DIM_RW                                     $5      !1, ~4
          8        ASSIGN_DIM_OP                +=               1          $5, 'TOTAL'
          9        OP_DATA                                                  ~7
   15    10      > JMP                                                      ->14
   18    11    >   FETCH_DIM_R                                      ~8      !0, 'ID'
         12        ASSIGN_DIM                                               !1, ~8
         13        OP_DATA                                                  !0
   20    14    > > RETURN                                                   null

End of Dynamic Function 0

End of function summtotal

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.94 ms | 1010 KiB | 17 Q