3v4l.org

run code in 300+ PHP versions simultaneously
<?php $qp = [ ['Nsd_id' => "1@2@3@4@5", 'Nsd_amount' => "0@0@0@20000@0"], ['Nsd_id' => "1@2@3@4@5", 'Nsd_amount' => "0@0@12000@0@0"], ['Nsd_id' => "1@2@3@4@5", 'Nsd_amount' => "0@0@0@10000@0"], ['Nsd_id' => "1@2@3@4@5", 'Nsd_amount' => "0@0@10000@0@0"], ['Nsd_id' => "1@2@3@4@5@12", 'Nsd_amount' => "0@0@10000@0@0@1000"], ['Nsd_id' => "1@2@3@4@5@12@14@15", 'Nsd_amount' => "0@0@8000@0@0@0@0@0"], ['Nsd_id' => "1@2@3@4@5@12@14@15", 'Nsd_amount' => "0@0@0@0@0@0@13000@0"], ['Nsd_id' => "1@2@3@4@5@12@14@15", 'Nsd_amount' => "0@2500@0@3900@0@0@20000@0"], ['Nsd_id' => "1@2@3@4@5@12@14@15", 'Nsd_amount' => "0@0@5000@0@0@0@0@0"], ['Nsd_id' => "1@2@3@4@5@12@14@15", 'Nsd_amount' => "0@0@5000@0@0@1000@0@0"], ['Nsd_id' => "1@2@3@4@5@12@14@15", 'Nsd_amount' => "0@0@2000@0@0@500@0@0"], ['Nsd_id' => "1@2@3@4@5@12@14@15", 'Nsd_amount' => "0@0@0@0@0@0@4000@0"], ]; $nsdIds = []; $result = []; foreach ($qp as $key => $value) { // exploding Nsd_ids $nsdTemp = explode("@", $value['Nsd_id']); // exploding nsd_amounts $nsdAmount = explode("@", $value['Nsd_amount']); // saving all new nsd ids and only keep unique nsd ids $nsdIds = array_unique(array_merge($nsdIds, $nsdTemp)); // I am now combining keeping nsd id as key and nsd amount as its value $temp1 = array_combine($nsdTemp, $nsdAmount); foreach ($nsdIds as $value1) { // for latest php version // $temp1 contains keys of nsd ids // value1 contains nsdids we are sure that it will be in nsdids as we are already merging those ids // then fetching amounf for that nsdids //$result[$value1] = ($result[$value1] ?? 0) + $temp1[$value1]; // for php version less than 7 $result[$value1] = (!empty($result[$value1]) ? $result[$value1] : 0) + (!empty($temp1[$value1]) ? $temp1[$value1] : 0); } } print_r($result);die;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 53
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 53
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 32, Position 2 = 51
Branch analysis from position: 32
2 jumps found. (Code = 78) Position 1 = 33, Position 2 = 51
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 39
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 46
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 46
Branch analysis from position: 43
Branch analysis from position: 46
Branch analysis from position: 51
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 51
Branch analysis from position: 53
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 53
filename:       /in/1Ymh7
function name:  (null)
number of ops:  59
compiled vars:  !0 = $qp, !1 = $nsdIds, !2 = $result, !3 = $value, !4 = $key, !5 = $nsdTemp, !6 = $nsdAmount, !7 = $temp1, !8 = $value1
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   17     1        ASSIGN                                                   !1, <array>
   18     2        ASSIGN                                                   !2, <array>
   19     3      > FE_RESET_R                                       $12     !0, ->53
          4    > > FE_FETCH_R                                       ~13     $12, !3, ->53
          5    >   ASSIGN                                                   !4, ~13
   21     6        INIT_FCALL                                               'explode'
          7        SEND_VAL                                                 '%40'
          8        FETCH_DIM_R                                      ~15     !3, 'Nsd_id'
          9        SEND_VAL                                                 ~15
         10        DO_ICALL                                         $16     
         11        ASSIGN                                                   !5, $16
   23    12        INIT_FCALL                                               'explode'
         13        SEND_VAL                                                 '%40'
         14        FETCH_DIM_R                                      ~18     !3, 'Nsd_amount'
         15        SEND_VAL                                                 ~18
         16        DO_ICALL                                         $19     
         17        ASSIGN                                                   !6, $19
   25    18        INIT_FCALL                                               'array_unique'
         19        INIT_FCALL                                               'array_merge'
         20        SEND_VAR                                                 !1
         21        SEND_VAR                                                 !5
         22        DO_ICALL                                         $21     
         23        SEND_VAR                                                 $21
         24        DO_ICALL                                         $22     
         25        ASSIGN                                                   !1, $22
   27    26        INIT_FCALL                                               'array_combine'
         27        SEND_VAR                                                 !5
         28        SEND_VAR                                                 !6
         29        DO_ICALL                                         $24     
         30        ASSIGN                                                   !7, $24
   29    31      > FE_RESET_R                                       $26     !1, ->51
         32    > > FE_FETCH_R                                               $26, !8, ->51
   36    33    >   ISSET_ISEMPTY_DIM_OBJ                         1  ~28     !2, !8
         34        BOOL_NOT                                         ~29     ~28
         35      > JMPZ                                                     ~29, ->39
         36    >   FETCH_DIM_R                                      ~30     !2, !8
         37        QM_ASSIGN                                        ~31     ~30
         38      > JMP                                                      ->40
         39    >   QM_ASSIGN                                        ~31     0
   37    40    >   ISSET_ISEMPTY_DIM_OBJ                         1  ~32     !7, !8
         41        BOOL_NOT                                         ~33     ~32
         42      > JMPZ                                                     ~33, ->46
         43    >   FETCH_DIM_R                                      ~34     !7, !8
         44        QM_ASSIGN                                        ~35     ~34
         45      > JMP                                                      ->47
         46    >   QM_ASSIGN                                        ~35     0
         47    >   ADD                                              ~36     ~31, ~35
   36    48        ASSIGN_DIM                                               !2, !8
   37    49        OP_DATA                                                  ~36
   29    50      > JMP                                                      ->32
         51    >   FE_FREE                                                  $26
   19    52      > JMP                                                      ->4
         53    >   FE_FREE                                                  $12
   40    54        INIT_FCALL                                               'print_r'
         55        SEND_VAR                                                 !2
         56        DO_ICALL                                                 
         57      > EXIT                                                     
   41    58*     > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.4 ms | 1009 KiB | 18 Q