3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json = '[{"clientName":"Audi","model":"A6","cost":40000},{"clientName":"Audi","model":"S8","cost":90000},{"clientName":"VW","model":"GolfV","cost":5000},{"clientName":"VW","model":"GolfV","cost":3500},{"clientName":"Audi","model":"RS6","cost":120000},{"clientName":"VW","model":"PassatCC","cost":35000}]'; $array = json_decode($json, true); $totals = []; $makes = []; $modelTotals = []; foreach ($array as $row) { // Set defaults to suppress notices $totals[$row['clientName']] = isset($totals[$row['clientName']]) ? $totals[$row['clientName']] : 0; $modelTotals[$row['model']] = isset($modelTotals[$row['model']]) ? $modelTotals[$row['model']] : 0; $totals[$row['clientName']] += $row['cost']; $makes[$row['clientName']][$row['model']] = $row; $modelTotals[$row['model']] += $row['cost']; } foreach($makes as $client => $cars) { echo $client.' total: '.$totals[$client]."\n"; foreach($cars as $model) { echo $model['model'].' '.$modelTotals[$model['model']]."\n"; } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 47
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 47
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 19
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 30
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 30
Branch analysis from position: 26
Branch analysis from position: 30
Branch analysis from position: 47
2 jumps found. (Code = 77) Position 1 = 49, Position 2 = 68
Branch analysis from position: 49
2 jumps found. (Code = 78) Position 1 = 50, Position 2 = 68
Branch analysis from position: 50
2 jumps found. (Code = 77) Position 1 = 57, Position 2 = 66
Branch analysis from position: 57
2 jumps found. (Code = 78) Position 1 = 58, Position 2 = 66
Branch analysis from position: 58
1 jumps found. (Code = 42) Position 1 = 57
Branch analysis from position: 57
Branch analysis from position: 66
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
Branch analysis from position: 66
Branch analysis from position: 68
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 68
Branch analysis from position: 47
filename:       /in/kbkng
function name:  (null)
number of ops:  70
compiled vars:  !0 = $json, !1 = $array, !2 = $totals, !3 = $makes, !4 = $modelTotals, !5 = $row, !6 = $cars, !7 = $client, !8 = $model
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%5B%7B%22clientName%22%3A%22Audi%22%2C%22model%22%3A%22A6%22%2C%22cost%22%3A40000%7D%2C%7B%22clientName%22%3A%22Audi%22%2C%22model%22%3A%22S8%22%2C%22cost%22%3A90000%7D%2C%7B%22clientName%22%3A%22VW%22%2C%22model%22%3A%22GolfV%22%2C%22cost%22%3A5000%7D%2C%7B%22clientName%22%3A%22VW%22%2C%22model%22%3A%22GolfV%22%2C%22cost%22%3A3500%7D%2C%7B%22clientName%22%3A%22Audi%22%2C%22model%22%3A%22RS6%22%2C%22cost%22%3A120000%7D%2C%7B%22clientName%22%3A%22VW%22%2C%22model%22%3A%22PassatCC%22%2C%22cost%22%3A35000%7D%5D'
    5     1        INIT_FCALL                                               'json_decode'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 <true>
          4        DO_ICALL                                         $10     
          5        ASSIGN                                                   !1, $10
    7     6        ASSIGN                                                   !2, <array>
    8     7        ASSIGN                                                   !3, <array>
    9     8        ASSIGN                                                   !4, <array>
   11     9      > FE_RESET_R                                       $15     !1, ->47
         10    > > FE_FETCH_R                                               $15, !5, ->47
   13    11    >   FETCH_DIM_R                                      ~16     !5, 'clientName'
         12        FETCH_DIM_R                                      ~18     !5, 'clientName'
         13        ISSET_ISEMPTY_DIM_OBJ                         0          !2, ~18
         14      > JMPZ                                                     ~19, ->19
         15    >   FETCH_DIM_R                                      ~20     !5, 'clientName'
         16        FETCH_DIM_R                                      ~21     !2, ~20
         17        QM_ASSIGN                                        ~22     ~21
         18      > JMP                                                      ->20
         19    >   QM_ASSIGN                                        ~22     0
         20    >   ASSIGN_DIM                                               !2, ~16
         21        OP_DATA                                                  ~22
   14    22        FETCH_DIM_R                                      ~23     !5, 'model'
         23        FETCH_DIM_R                                      ~25     !5, 'model'
         24        ISSET_ISEMPTY_DIM_OBJ                         0          !4, ~25
         25      > JMPZ                                                     ~26, ->30
         26    >   FETCH_DIM_R                                      ~27     !5, 'model'
         27        FETCH_DIM_R                                      ~28     !4, ~27
         28        QM_ASSIGN                                        ~29     ~28
         29      > JMP                                                      ->31
         30    >   QM_ASSIGN                                        ~29     0
         31    >   ASSIGN_DIM                                               !4, ~23
         32        OP_DATA                                                  ~29
   16    33        FETCH_DIM_R                                      ~30     !5, 'clientName'
         34        FETCH_DIM_R                                      ~32     !5, 'cost'
         35        ASSIGN_DIM_OP                +=               1          !2, ~30
         36        OP_DATA                                                  ~32
   17    37        FETCH_DIM_R                                      ~33     !5, 'clientName'
         38        FETCH_DIM_R                                      ~35     !5, 'model'
         39        FETCH_DIM_W                                      $34     !3, ~33
         40        ASSIGN_DIM                                               $34, ~35
         41        OP_DATA                                                  !5
   18    42        FETCH_DIM_R                                      ~37     !5, 'model'
         43        FETCH_DIM_R                                      ~39     !5, 'cost'
         44        ASSIGN_DIM_OP                +=               1          !4, ~37
         45        OP_DATA                                                  ~39
   11    46      > JMP                                                      ->10
         47    >   FE_FREE                                                  $15
   21    48      > FE_RESET_R                                       $40     !3, ->68
         49    > > FE_FETCH_R                                       ~41     $40, !6, ->68
         50    >   ASSIGN                                                   !7, ~41
   22    51        CONCAT                                           ~43     !7, '+total%3A+'
         52        FETCH_DIM_R                                      ~44     !2, !7
         53        CONCAT                                           ~45     ~43, ~44
         54        CONCAT                                           ~46     ~45, '%0A'
         55        ECHO                                                     ~46
   23    56      > FE_RESET_R                                       $47     !6, ->66
         57    > > FE_FETCH_R                                               $47, !8, ->66
   24    58    >   FETCH_DIM_R                                      ~48     !8, 'model'
         59        CONCAT                                           ~49     ~48, '+'
         60        FETCH_DIM_R                                      ~50     !8, 'model'
         61        FETCH_DIM_R                                      ~51     !4, ~50
         62        CONCAT                                           ~52     ~49, ~51
         63        CONCAT                                           ~53     ~52, '%0A'
         64        ECHO                                                     ~53
   23    65      > JMP                                                      ->57
         66    >   FE_FREE                                                  $47
   21    67      > JMP                                                      ->49
         68    >   FE_FREE                                                  $40
   26    69      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.4 ms | 1009 KiB | 14 Q