3v4l.org

run code in 500+ PHP versions simultaneously
<?php class Info { public function __construct(public int $count) {} } $ballsToDolls = [1 => [11 => new Info(3), 22 => new Info(4)], 2 => [22 => new Info(5), 44 => new Info(6)]]; print_r($ballsToDolls); $data = []; foreach ($ballsToDolls as $ballId => $dolls) { foreach ($dolls as $dollId => $info) { $data[$ballId][$dollId] = ($data[$ballId][$dollId] ?? 0) + $info->count; } } print_r($data); $data = $ballsToDolls; array_walk_recursive($data, static function(&$item, $key) { $item = $item instanceof Info ? $item->count : $item; }); print_r($data);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 24, Position 2 = 41
Branch analysis from position: 24
2 jumps found. (Code = 78) Position 1 = 25, Position 2 = 41
Branch analysis from position: 25
2 jumps found. (Code = 77) Position 1 = 27, Position 2 = 39
Branch analysis from position: 27
2 jumps found. (Code = 78) Position 1 = 28, Position 2 = 39
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 39
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
filename:       /in/SvG3l
function name:  (null)
number of ops:  55
compiled vars:  !0 = $ballsToDolls, !1 = $data, !2 = $dolls, !3 = $ballId, !4 = $info, !5 = $dollId
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    7     0  E >   NEW                                                  $6      'Info'
          1        SEND_VAL_EX                                                  3
          2        DO_FCALL                                          0          
          3        INIT_ARRAY                                           ~8      $6, 11
          4        NEW                                                  $9      'Info'
          5        SEND_VAL_EX                                                  4
          6        DO_FCALL                                          0          
          7        ADD_ARRAY_ELEMENT                                    ~8      $9, 22
          8        INIT_ARRAY                                           ~11     ~8, 1
          9        NEW                                                  $12     'Info'
         10        SEND_VAL_EX                                                  5
         11        DO_FCALL                                          0          
         12        INIT_ARRAY                                           ~14     $12, 22
         13        NEW                                                  $15     'Info'
         14        SEND_VAL_EX                                                  6
         15        DO_FCALL                                          0          
         16        ADD_ARRAY_ELEMENT                                    ~14     $15, 44
         17        ADD_ARRAY_ELEMENT                                    ~11     ~14, 2
         18        ASSIGN                                                       !0, ~11
    8    19        INIT_FCALL                                                   'print_r'
         20        SEND_VAR                                                     !0
         21        DO_ICALL                                                     
   10    22        ASSIGN                                                       !1, <array>
   11    23      > FE_RESET_R                                           $20     !0, ->41
         24    > > FE_FETCH_R                                           ~21     $20, !2, ->41
         25    >   ASSIGN                                                       !3, ~21
   12    26      > FE_RESET_R                                           $23     !2, ->39
         27    > > FE_FETCH_R                                           ~24     $23, !4, ->39
         28    >   ASSIGN                                                       !5, ~24
   13    29        FETCH_DIM_IS                                         ~28     !1, !3
         30        FETCH_DIM_IS                                         ~29     ~28, !5
         31        COALESCE                                             ~30     ~29
         32        QM_ASSIGN                                            ~30     0
         33        FETCH_OBJ_R                                          ~31     !4, 'count'
         34        ADD                                                  ~32     ~30, ~31
         35        FETCH_DIM_W                                          $26     !1, !3
         36        ASSIGN_DIM                                                   $26, !5
         37        OP_DATA                                                      ~32
   12    38      > JMP                                                          ->27
         39    >   FE_FREE                                                      $23
   11    40      > JMP                                                          ->24
         41    >   FE_FREE                                                      $20
   16    42        INIT_FCALL                                                   'print_r'
         43        SEND_VAR                                                     !1
         44        DO_ICALL                                                     
   18    45        ASSIGN                                                       !1, !0
   19    46        INIT_FCALL                                                   'array_walk_recursive'
         47        SEND_REF                                                     !1
         48        DECLARE_LAMBDA_FUNCTION                              ~35     [0]
   21    49        SEND_VAL                                                     ~35
   19    50        DO_ICALL                                                     
   22    51        INIT_FCALL                                                   'print_r'
         52        SEND_VAR                                                     !1
         53        DO_ICALL                                                     
         54      > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SvG3l
function name:  {closure:/in/SvG3l:19}
number of ops:  10
compiled vars:  !0 = $item, !1 = $key
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   19     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   20     2        INSTANCEOF                                                   !0, 'Info'
          3      > JMPZ                                                         ~2, ->7
          4    >   FETCH_OBJ_R                                          ~3      !0, 'count'
          5        QM_ASSIGN                                            ~4      ~3
          6      > JMP                                                          ->8
          7    >   QM_ASSIGN                                            ~4      !0
          8    >   ASSIGN                                                       !0, ~4
   21     9      > RETURN                                                       null

End of Dynamic Function 0

Class Info:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SvG3l
function name:  __construct
number of ops:  4
compiled vars:  !0 = $count
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    4     0  E >   RECV                                                 !0      
          1        ASSIGN_OBJ                                                   'count'
          2        OP_DATA                                                      !0
          3      > RETURN                                                       null

End of function __construct

End of class Info.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
165.06 ms | 1533 KiB | 15 Q