3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = <<<EOL [ { "tax": "10", "concept": "TUC", "val": "10" }, { "tax": "10", "concept": "TUC", "val": "86" }, { "tax": "15", "concept": "TUC", "val": "8" }, { "tax": "11", "concept": "IPS", "val": "6" }, { "tax": "11", "concept": "IPS", "val": "45" } ] EOL; $array = json_decode($str); $result = array_reduce($array, function($carry, $item) { if(!isset($carry[$item->tax])) { $carry[$item->tax] = $item; } else { $carry[$item->tax]->val += $item->val; } return $carry; }); $result = array_values($result); print_r(json_encode($result));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ndnbQ
function name:  (null)
number of ops:  22
compiled vars:  !0 = $str, !1 = $array, !2 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%5B%0A+%7B%0A++++%22tax%22%3A+%2210%22%2C%0A++++%22concept%22%3A+%22TUC%22%2C%0A++++%22val%22%3A+%2210%22%0A+%7D%2C%0A+%7B%0A++++%22tax%22%3A+%2210%22%2C%0A++++%22concept%22%3A+%22TUC%22%2C%0A++++%22val%22%3A+%2286%22%0A+%7D%2C%0A+%7B%0A++++%22tax%22%3A+%2215%22%2C%0A++++%22concept%22%3A+%22TUC%22%2C%0A++++%22val%22%3A+%228%22%0A+%7D%2C%0A+%7B%0A++++%22tax%22%3A+%2211%22%2C%0A++++%22concept%22%3A+%22IPS%22%2C%0A++++%22val%22%3A+%226%22%0A+%7D%2C%0A+%7B%0A++++%22tax%22%3A+%2211%22%2C%0A++++%22concept%22%3A+%22IPS%22%2C%0A++++%22val%22%3A+%2245%22%0A+%7D++%0A%5D'
   32     1        INIT_FCALL                                               'json_decode'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $4      
          4        ASSIGN                                                   !1, $4
   34     5        INIT_FCALL                                               'array_reduce'
          6        SEND_VAR                                                 !1
          7        DECLARE_LAMBDA_FUNCTION                          ~6      [0]
   41     8        SEND_VAL                                                 ~6
   34     9        DO_ICALL                                         $7      
         10        ASSIGN                                                   !2, $7
   43    11        INIT_FCALL                                               'array_values'
         12        SEND_VAR                                                 !2
         13        DO_ICALL                                         $9      
         14        ASSIGN                                                   !2, $9
   45    15        INIT_FCALL                                               'print_r'
         16        INIT_FCALL                                               'json_encode'
         17        SEND_VAR                                                 !2
         18        DO_ICALL                                         $11     
         19        SEND_VAR                                                 $11
         20        DO_ICALL                                                 
         21      > 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 = 42) Position 1 = 15
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ndnbQ
function name:  {closure}
number of ops:  17
compiled vars:  !0 = $carry, !1 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   35     2        FETCH_OBJ_R                                      ~2      !1, 'tax'
          3        ISSET_ISEMPTY_DIM_OBJ                         0  ~3      !0, ~2
          4        BOOL_NOT                                         ~4      ~3
          5      > JMPZ                                                     ~4, ->10
   36     6    >   FETCH_OBJ_R                                      ~5      !1, 'tax'
          7        ASSIGN_DIM                                               !0, ~5
          8        OP_DATA                                                  !1
   35     9      > JMP                                                      ->15
   38    10    >   FETCH_OBJ_R                                      ~7      !1, 'tax'
         11        FETCH_OBJ_R                                      ~10     !1, 'val'
         12        FETCH_DIM_RW                                     $8      !0, ~7
         13        ASSIGN_OBJ_OP                                 1          $8, 'val'
         14        OP_DATA                                                  ~10
   40    15    > > RETURN                                                   !0
   41    16*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.41 ms | 994 KiB | 18 Q