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); $sku = $row[0]; //#2 cat remapping assert(isset($catMap[$row[3]])); $row[3] = $catMap[$row[3]]; //combining if(isset($result[$sku])){ $result[$sku][2] .= ' ' . $row[2]; }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 = 34
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 34
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 31
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
filename:       /in/85EHX
function name:  (null)
number of ops:  39
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, ->34
          4    > > FE_FETCH_R                                               $8, !3, ->34
   18     5    >   INIT_FCALL                                               'array_map'
          6        SEND_VAL                                                 'trim'
          7        SEND_VAR                                                 !3
          8        DO_ICALL                                         $9      
          9        ASSIGN                                                   !3, $9
   20    10        FETCH_DIM_R                                      ~11     !3, 0
         11        ASSIGN                                                   !4, ~11
   23    12        ASSERT_CHECK                                             
         13        INIT_FCALL                                               'assert'
         14        FETCH_DIM_R                                      ~13     !3, 3
         15        ISSET_ISEMPTY_DIM_OBJ                         0  ~14     !1, ~13
         16        SEND_VAL                                                 ~14
         17        SEND_VAL                                                 'assert%28isset%28%24catMap%5B%24row%5B3%5D%5D%29%29'
         18        DO_ICALL                                                 
   24    19        FETCH_DIM_R                                      ~17     !3, 3
         20        FETCH_DIM_R                                      ~18     !1, ~17
         21        ASSIGN_DIM                                               !3, 3
         22        OP_DATA                                                  ~18
   27    23        ISSET_ISEMPTY_DIM_OBJ                         0          !2, !4
         24      > JMPZ                                                     ~19, ->31
   28    25    >   FETCH_DIM_R                                      ~22     !3, 2
         26        CONCAT                                           ~23     '+', ~22
         27        FETCH_DIM_RW                                     $20     !2, !4
         28        ASSIGN_DIM_OP                .=               8          $20, 2
         29        OP_DATA                                                  ~23
         30      > JMP                                                      ->33
   30    31    >   ASSIGN_DIM                                               !2, !4
         32        OP_DATA                                                  !3
   16    33    > > JMP                                                      ->4
         34    >   FE_FREE                                                  $8
   34    35        INIT_FCALL                                               'var_dump'
         36        SEND_VAR                                                 !2
         37        DO_ICALL                                                 
         38      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
191.99 ms | 1400 KiB | 19 Q