3v4l.org

run code in 300+ PHP versions simultaneously
<?php $testHeader = ['Mold SKU', 'Title', 'Category', 'Tags']; $testRows = []; $testRows[] = ['12MM-SM-SQ', '12mm Squares', 'Earings|Earings > Fishhooks','square']; $testRows[] = ['12MM-SQ-HOLLOW-DROP', 'Square Hollow Drop Studs', 'Earings|Earings > Studs','square']; $testRows[] = ['Example SKU', 'Example Title', 'Example|Sub|Whatever|category','tag1|tag2|tag3']; $testArray = [$testHeader, ...$testRows]; $fp = fopen('php://memory', 'w+'); foreach ($testArray as $testRow) { fputcsv($fp, $testRow); } rewind($fp); // ABOVE IS ONLY FOR TESTING HERE! ------------------------------------- // $fp = fopen($skufileurl, 'r'); // <-- you will use this! $termName = 'Example SKU'; $csvRows = []; $csvHeader = fgetcsv($fp); while ($csvRow = fgetcsv($fp)) { $keyedCsvRow = array_combine($csvHeader, $csvRow); if ($keyedCsvRow['Mold SKU'] === $termName) { $keyedCsvRow['Category'] = explode('|', $keyedCsvRow['Category']); $keyedCsvRow['Tags'] = explode('|', $keyedCsvRow['Tags']); $finalArray = $keyedCsvRow; break; } } var_dump($finalArray);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 23
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 23
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 58
Branch analysis from position: 58
2 jumps found. (Code = 44) Position 1 = 63, Position 2 = 34
Branch analysis from position: 63
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 58
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 63
Branch analysis from position: 63
Branch analysis from position: 58
Branch analysis from position: 23
filename:       /in/hg07O
function name:  (null)
number of ops:  67
compiled vars:  !0 = $testHeader, !1 = $testRows, !2 = $testArray, !3 = $fp, !4 = $testRow, !5 = $termName, !6 = $csvRows, !7 = $csvHeader, !8 = $keyedCsvRow, !9 = $csvRow, !10 = $finalArray
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1        ASSIGN                                                   !1, <array>
    5     2        ASSIGN_DIM                                               !1
          3        OP_DATA                                                  <array>
    6     4        ASSIGN_DIM                                               !1
          5        OP_DATA                                                  <array>
    7     6        ASSIGN_DIM                                               !1
          7        OP_DATA                                                  <array>
    9     8        INIT_ARRAY                                       ~16     !0
          9        ADD_ARRAY_UNPACK                                 ~16     !1
         10        ASSIGN                                                   !2, ~16
   11    11        INIT_FCALL                                               'fopen'
         12        SEND_VAL                                                 'php%3A%2F%2Fmemory'
         13        SEND_VAL                                                 'w%2B'
         14        DO_ICALL                                         $18     
         15        ASSIGN                                                   !3, $18
   12    16      > FE_RESET_R                                       $20     !2, ->23
         17    > > FE_FETCH_R                                               $20, !4, ->23
   13    18    >   INIT_FCALL                                               'fputcsv'
         19        SEND_VAR                                                 !3
         20        SEND_VAR                                                 !4
         21        DO_ICALL                                                 
   12    22      > JMP                                                      ->17
         23    >   FE_FREE                                                  $20
   15    24        INIT_FCALL                                               'rewind'
         25        SEND_VAR                                                 !3
         26        DO_ICALL                                                 
   19    27        ASSIGN                                                   !5, 'Example+SKU'
   21    28        ASSIGN                                                   !6, <array>
   22    29        INIT_FCALL                                               'fgetcsv'
         30        SEND_VAR                                                 !3
         31        DO_ICALL                                         $25     
         32        ASSIGN                                                   !7, $25
   23    33      > JMP                                                      ->58
   24    34    >   INIT_FCALL                                               'array_combine'
         35        SEND_VAR                                                 !7
         36        SEND_VAR                                                 !9
         37        DO_ICALL                                         $27     
         38        ASSIGN                                                   !8, $27
   26    39        FETCH_DIM_R                                      ~29     !8, 'Mold+SKU'
         40        IS_IDENTICAL                                             !5, ~29
         41      > JMPZ                                                     ~30, ->58
   27    42    >   INIT_FCALL                                               'explode'
         43        SEND_VAL                                                 '%7C'
         44        FETCH_DIM_R                                      ~32     !8, 'Category'
         45        SEND_VAL                                                 ~32
         46        DO_ICALL                                         $33     
         47        ASSIGN_DIM                                               !8, 'Category'
         48        OP_DATA                                                  $33
   28    49        INIT_FCALL                                               'explode'
         50        SEND_VAL                                                 '%7C'
         51        FETCH_DIM_R                                      ~35     !8, 'Tags'
         52        SEND_VAL                                                 ~35
         53        DO_ICALL                                         $36     
         54        ASSIGN_DIM                                               !8, 'Tags'
         55        OP_DATA                                                  $36
   30    56        ASSIGN                                                   !10, !8
   31    57      > JMP                                                      ->63
   23    58    >   INIT_FCALL                                               'fgetcsv'
         59        SEND_VAR                                                 !3
         60        DO_ICALL                                         $38     
         61        ASSIGN                                           ~39     !9, $38
         62      > JMPNZ                                                    ~39, ->34
   35    63    >   INIT_FCALL                                               'var_dump'
         64        SEND_VAR                                                 !10
         65        DO_ICALL                                                 
         66      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.69 ms | 1013 KiB | 20 Q