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) + $result[$temp1[$value1]]; } } print_r($result);die;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 43
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 43
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 32, Position 2 = 41
Branch analysis from position: 32
2 jumps found. (Code = 78) Position 1 = 33, Position 2 = 41
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 41
Branch analysis from position: 43
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 43
filename:       /in/qnK1X
function name:  (null)
number of ops:  49
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
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   16     1        ASSIGN                                                   !1, <array>
   17     2        ASSIGN                                                   !2, <array>
   18     3      > FE_RESET_R                                       $12     !0, ->43
          4    > > FE_FETCH_R                                       ~13     $12, !3, ->43
          5    >   ASSIGN                                                   !4, ~13
   20     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
   22    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
   24    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
   26    26        INIT_FCALL                                               'array_combine'
         27        SEND_VAR                                                 !5
         28        SEND_VAR                                                 !6
         29        DO_ICALL                                         $24     
         30        ASSIGN                                                   !7, $24
   28    31      > FE_RESET_R                                       $26     !1, ->41
         32    > > FE_FETCH_R                                               $26, !8, ->41
   33    33    >   FETCH_DIM_IS                                     ~28     !2, !8
         34        COALESCE                                         ~29     ~28
         35        QM_ASSIGN                                        ~29     0
         36        FETCH_DIM_R                                      ~30     !7, !8
         37        ADD                                              ~31     ~29, ~30
         38        ASSIGN_DIM                                               !2, !8
         39        OP_DATA                                                  ~31
   28    40      > JMP                                                      ->32
         41    >   FE_FREE                                                  $26
   18    42      > JMP                                                      ->4
         43    >   FE_FREE                                                  $12
   39    44        INIT_FCALL                                               'print_r'
         45        SEND_VAR                                                 !2
         46        DO_ICALL                                                 
         47      > EXIT                                                     
   40    48*     > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.35 ms | 1009 KiB | 18 Q