3v4l.org

run code in 300+ PHP versions simultaneously
<?php function checkIfJobAlreadyExistsAndUpdateCsv(array $csvRows) { $thisJob = false; $existingJobsAndItsDetails = []; $items = []; foreach ($csvRows as $index => $row) { echo PHP_EOL . 'This is row 0 value: '. $row[0]; if ($row[0] === 'H') { $thisJob = false; echo PHP_EOL . 'This job number: ' . $thisJob; if ($row[1] == 'BB2') { $thisJob = $row[1]; $existingJobsAndItsDetails[$thisJob]= $thisJob; unset($csvRows[$index]); } } if ($row[0] === 'D' && $thisJob) { echo PHP_EOL . 'This item number: ' . $row[1]; $items[$thisJob][] = $row; unset($csvRows[$index]); } } echo PHP_EOL . 'Final Array: '; foreach ($existingJobsAndItsDetails as $jobId => $thisJob) { echo PHP_EOL . 'This job number: ' . $thisJob; if (isset($items[$thisJob])) { foreach ($items[$thisJob] as $itemRow) { $productCode = $itemRow[1]; echo PHP_EOL . print_r($productCode, 1); } } } return $existingJobsAndItsDetails; } $myArray = [['H','AA1 ','598.12'], ['D','itemA1','PRAWN: KING - BAP - RAW PEELED DEVEINED 16-20 (700GM NETT PACK)'], ['D','itemA2','HADDOCK: FILLET 220-280GM SKINNED (KG)'], ['D','itemA3','SEABASS: WILD - WHOLE 2-3KG (KG)'], ['D','itemA4','MACKEREL: FILLETED LARGE (KG)'], ['H','BB2','68.93'], ['D','itemB1','TUNA : SASHIMI GRADE - LOIN ( KG )'], ['H','CC3','8.5']]; echo print_r(checkIfJobAlreadyExistsAndUpdateCsv($myArray), 1);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/dcL2C
function name:  (null)
number of ops:  10
compiled vars:  !0 = $myArray
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   ASSIGN                                                   !0, <array>
   53     1        INIT_FCALL                                               'print_r'
          2        INIT_FCALL                                               'checkifjobalreadyexistsandupdatecsv'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        SEND_VAL                                                 1
          7        DO_ICALL                                         $3      
          8        ECHO                                                     $3
          9      > RETURN                                                   1

Function checkifjobalreadyexistsandupdatecsv:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 37
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 37
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 24
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 24
Branch analysis from position: 19
2 jumps found. (Code = 46) Position 1 = 27, Position 2 = 28
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 36
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 36
Branch analysis from position: 28
Branch analysis from position: 24
Branch analysis from position: 24
Branch analysis from position: 37
2 jumps found. (Code = 77) Position 1 = 40, Position 2 = 60
Branch analysis from position: 40
2 jumps found. (Code = 78) Position 1 = 41, Position 2 = 60
Branch analysis from position: 41
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 59
Branch analysis from position: 46
2 jumps found. (Code = 77) Position 1 = 48, Position 2 = 58
Branch analysis from position: 48
2 jumps found. (Code = 78) Position 1 = 49, Position 2 = 58
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
Branch analysis from position: 58
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
Branch analysis from position: 58
Branch analysis from position: 59
Branch analysis from position: 60
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 60
Branch analysis from position: 37
filename:       /in/dcL2C
function name:  checkIfJobAlreadyExistsAndUpdateCsv
number of ops:  63
compiled vars:  !0 = $csvRows, !1 = $thisJob, !2 = $existingJobsAndItsDetails, !3 = $items, !4 = $row, !5 = $index, !6 = $jobId, !7 = $itemRow, !8 = $productCode
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    4     1        ASSIGN                                                   !1, <false>
    5     2        ASSIGN                                                   !2, <array>
    6     3        ASSIGN                                                   !3, <array>
    7     4      > FE_RESET_R                                       $12     !0, ->37
          5    > > FE_FETCH_R                                       ~13     $12, !4, ->37
          6    >   ASSIGN                                                   !5, ~13
    8     7        FETCH_DIM_R                                      ~15     !4, 0
          8        CONCAT                                           ~16     '%0AThis+is+row+0+value%3A+', ~15
          9        ECHO                                                     ~16
    9    10        FETCH_DIM_R                                      ~17     !4, 0
         11        IS_IDENTICAL                                             ~17, 'H'
         12      > JMPZ                                                     ~18, ->24
   10    13    >   ASSIGN                                                   !1, <false>
   13    14        CONCAT                                           ~20     '%0AThis+job+number%3A+', !1
         15        ECHO                                                     ~20
   14    16        FETCH_DIM_R                                      ~21     !4, 1
         17        IS_EQUAL                                                 ~21, 'BB2'
         18      > JMPZ                                                     ~22, ->24
   15    19    >   FETCH_DIM_R                                      ~23     !4, 1
         20        ASSIGN                                                   !1, ~23
   16    21        ASSIGN_DIM                                               !2, !1
         22        OP_DATA                                                  !1
   17    23        UNSET_DIM                                                !0, !5
   21    24    >   FETCH_DIM_R                                      ~26     !4, 0
         25        IS_IDENTICAL                                     ~27     ~26, 'D'
         26      > JMPZ_EX                                          ~27     ~27, ->28
         27    >   BOOL                                             ~27     !1
         28    > > JMPZ                                                     ~27, ->36
   22    29    >   FETCH_DIM_R                                      ~28     !4, 1
         30        CONCAT                                           ~29     '%0AThis+item+number%3A+', ~28
         31        ECHO                                                     ~29
   23    32        FETCH_DIM_W                                      $30     !3, !1
         33        ASSIGN_DIM                                               $30
         34        OP_DATA                                                  !4
   24    35        UNSET_DIM                                                !0, !5
    7    36    > > JMP                                                      ->5
         37    >   FE_FREE                                                  $12
   29    38        ECHO                                                     '%0AFinal+Array%3A+'
   30    39      > FE_RESET_R                                       $32     !2, ->60
         40    > > FE_FETCH_R                                       ~33     $32, !1, ->60
         41    >   ASSIGN                                                   !6, ~33
   31    42        CONCAT                                           ~35     '%0AThis+job+number%3A+', !1
         43        ECHO                                                     ~35
   32    44        ISSET_ISEMPTY_DIM_OBJ                         0          !3, !1
         45      > JMPZ                                                     ~36, ->59
   33    46    >   FETCH_DIM_R                                      ~37     !3, !1
         47      > FE_RESET_R                                       $38     ~37, ->58
         48    > > FE_FETCH_R                                               $38, !7, ->58
   34    49    >   FETCH_DIM_R                                      ~39     !7, 1
         50        ASSIGN                                                   !8, ~39
   35    51        INIT_FCALL                                               'print_r'
         52        SEND_VAR                                                 !8
         53        SEND_VAL                                                 1
         54        DO_ICALL                                         $41     
         55        CONCAT                                           ~42     '%0A', $41
         56        ECHO                                                     ~42
   33    57      > JMP                                                      ->48
         58    >   FE_FREE                                                  $38
   30    59    > > JMP                                                      ->40
         60    >   FE_FREE                                                  $32
   41    61      > RETURN                                                   !2
   42    62*     > RETURN                                                   null

End of function checkifjobalreadyexistsandupdatecsv

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
168.93 ms | 1407 KiB | 16 Q