3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arrays = [ [ "sender" => "userA", "value" => 10, "function" => "deposit" ], [ "sender" => "userB", "value" => 5, "function" => "deposit" ], [ "sender" => "userA", "value" => 2, "function" => "withdraw" ], [ "sender" => "userA", "value" => 3, "function" => "deposit" ], [ "sender" => "userA", "value" => 20, "function" => "deposit" ], [ "sender" => "userC", "value" => 99, "function" => "withdraw" ] ]; $result = array_reduce($arrays, function ($acc, $curr) { if (array_key_exists($curr["sender"], $acc)) { if ($curr["function"] === "deposit") { $acc[$curr["sender"]] += $curr["value"]; } if ($curr["function"] === "withdraw") { $acc[$curr["sender"]] -= $curr["value"]; } } else { if ($curr["function"] === "deposit") { $acc[$curr["sender"]] = $curr["value"]; } if ($curr["function"] === "withdraw") { $acc[$curr["sender"]] = -1 * $curr["value"]; } } return $acc; }, []); print_r($result);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/C8r1L
function name:  (null)
number of ops:  12
compiled vars:  !0 = $arrays, !1 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   36     1        INIT_FCALL                                               'array_reduce'
          2        SEND_VAR                                                 !0
          3        DECLARE_LAMBDA_FUNCTION                          ~3      [0]
   53     4        SEND_VAL                                                 ~3
          5        SEND_VAL                                                 <array>
   36     6        DO_ICALL                                         $4      
          7        ASSIGN                                                   !1, $4
   55     8        INIT_FCALL                                               'print_r'
          9        SEND_VAR                                                 !1
         10        DO_ICALL                                                 
         11      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 20
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 12
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 19
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
Branch analysis from position: 12
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 27
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 35
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
Branch analysis from position: 27
filename:       /in/C8r1L
function name:  {closure}
number of ops:  37
compiled vars:  !0 = $acc, !1 = $curr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   37     2        FETCH_DIM_R                                      ~2      !1, 'sender'
          3        ARRAY_KEY_EXISTS                                         ~2, !0
          4      > JMPZ                                                     ~3, ->20
   38     5    >   FETCH_DIM_R                                      ~4      !1, 'function'
          6        IS_IDENTICAL                                             ~4, 'deposit'
          7      > JMPZ                                                     ~5, ->12
   39     8    >   FETCH_DIM_R                                      ~6      !1, 'sender'
          9        FETCH_DIM_R                                      ~8      !1, 'value'
         10        ASSIGN_DIM_OP                +=               1          !0, ~6
         11        OP_DATA                                                  ~8
   41    12    >   FETCH_DIM_R                                      ~9      !1, 'function'
         13        IS_IDENTICAL                                             ~9, 'withdraw'
         14      > JMPZ                                                     ~10, ->19
   42    15    >   FETCH_DIM_R                                      ~11     !1, 'sender'
         16        FETCH_DIM_R                                      ~13     !1, 'value'
         17        ASSIGN_DIM_OP                -=               2          !0, ~11
         18        OP_DATA                                                  ~13
   37    19    > > JMP                                                      ->35
   45    20    >   FETCH_DIM_R                                      ~14     !1, 'function'
         21        IS_IDENTICAL                                             ~14, 'deposit'
         22      > JMPZ                                                     ~15, ->27
   46    23    >   FETCH_DIM_R                                      ~16     !1, 'sender'
         24        FETCH_DIM_R                                      ~18     !1, 'value'
         25        ASSIGN_DIM                                               !0, ~16
         26        OP_DATA                                                  ~18
   48    27    >   FETCH_DIM_R                                      ~19     !1, 'function'
         28        IS_IDENTICAL                                             ~19, 'withdraw'
         29      > JMPZ                                                     ~20, ->35
   49    30    >   FETCH_DIM_R                                      ~21     !1, 'sender'
         31        FETCH_DIM_R                                      ~23     !1, 'value'
         32        MUL                                              ~24     ~23, -1
         33        ASSIGN_DIM                                               !0, ~21
         34        OP_DATA                                                  ~24
   52    35    > > RETURN                                                   !0
   53    36*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.47 ms | 1008 KiB | 15 Q