3v4l.org

run code in 300+ PHP versions simultaneously
<?php $csv = [ ['s1','n1','description 1', 'Helmets'], ['s1','n1','description 1a', 'Helmets'], ['s2','n1','description 2', 'Gloves'], ['s2','n1','description 2a', 'Gloves'], ]; $catMap = [ 'Helmets' => 30, 'Gloves' => 20, ]; $result = []; foreach($csv as $row){ //#1 trimming: $row = array_map('trim', $row); $row = [ 'SKU' => $row[0], 'Product_Name' => $row[1], 'Description' => $row[2], 'Category_ID' => $row[3], ]; $sku = $row['SKU']; //#2 cat remapping assert(isset($catMap[$row['Category_ID']])); $row['Category_ID'] = $catMap[$row['Category_ID']]; //#3 combining if(isset($result[$sku])){ $result[$sku]['Description'] .= ' ' . $row['Description']; }else{ $result[$sku] = $row; } }; var_dump($result);
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 = 43) Position 1 = 34, Position 2 = 40
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 43
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 43
filename:       /in/tYDua
function name:  (null)
number of ops:  48
compiled vars:  !0 = $csv, !1 = $catMap, !2 = $result, !3 = $row, !4 = $sku
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   10     1        ASSIGN                                                   !1, <array>
   15     2        ASSIGN                                                   !2, <array>
   16     3      > FE_RESET_R                                       $8      !0, ->43
          4    > > FE_FETCH_R                                               $8, !3, ->43
   18     5    >   INIT_FCALL                                               'array_map'
          6        SEND_VAL                                                 'trim'
          7        SEND_VAR                                                 !3
          8        DO_ICALL                                         $9      
          9        ASSIGN                                                   !3, $9
   21    10        FETCH_DIM_R                                      ~11     !3, 0
         11        INIT_ARRAY                                       ~12     ~11, 'SKU'
   22    12        FETCH_DIM_R                                      ~13     !3, 1
         13        ADD_ARRAY_ELEMENT                                ~12     ~13, 'Product_Name'
   23    14        FETCH_DIM_R                                      ~14     !3, 2
         15        ADD_ARRAY_ELEMENT                                ~12     ~14, 'Description'
   24    16        FETCH_DIM_R                                      ~15     !3, 3
         17        ADD_ARRAY_ELEMENT                                ~12     ~15, 'Category_ID'
   20    18        ASSIGN                                                   !3, ~12
   27    19        FETCH_DIM_R                                      ~17     !3, 'SKU'
         20        ASSIGN                                                   !4, ~17
   30    21        ASSERT_CHECK                                             
         22        INIT_FCALL                                               'assert'
         23        FETCH_DIM_R                                      ~19     !3, 'Category_ID'
         24        ISSET_ISEMPTY_DIM_OBJ                         0  ~20     !1, ~19
         25        SEND_VAL                                                 ~20
         26        SEND_VAL                                                 'assert%28isset%28%24catMap%5B%24row%5B%27Category_ID%27%5D%5D%29%29'
         27        DO_ICALL                                                 
   31    28        FETCH_DIM_R                                      ~23     !3, 'Category_ID'
         29        FETCH_DIM_R                                      ~24     !1, ~23
         30        ASSIGN_DIM                                               !3, 'Category_ID'
         31        OP_DATA                                                  ~24
   34    32        ISSET_ISEMPTY_DIM_OBJ                         0          !2, !4
         33      > JMPZ                                                     ~25, ->40
   35    34    >   FETCH_DIM_R                                      ~28     !3, 'Description'
         35        CONCAT                                           ~29     '+', ~28
         36        FETCH_DIM_RW                                     $26     !2, !4
         37        ASSIGN_DIM_OP                .=               8          $26, 'Description'
         38        OP_DATA                                                  ~29
         39      > JMP                                                      ->42
   37    40    >   ASSIGN_DIM                                               !2, !4
         41        OP_DATA                                                  !3
   16    42    > > JMP                                                      ->4
         43    >   FE_FREE                                                  $8
   41    44        INIT_FCALL                                               'var_dump'
         45        SEND_VAR                                                 !2
         46        DO_ICALL                                                 
         47      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
173.75 ms | 1400 KiB | 19 Q