3v4l.org

run code in 300+ PHP versions simultaneously
<?php $desc = "GLOVE EXAM BEST TCH ALOE LTX MED 100/BX 10BX/CS"; $uom = "CS"; $keywords = explode(" ", $desc); $pkgstring = ""; $result = []; foreach ($keywords as $key => $keyword){ $firstchar = substr($keyword, 0, 1); if (is_numeric($firstchar)) { $pkgstring .= $keyword.","; } } $pkgstring = substr($pkgstring, 0, -1); $result['pkgstring'] = $pkgstring; $str_ele = explode(",", $pkgstring); $qty_uom = 1; $new_arr[0] = ""; $pos = 1; if (stripos($pkgstring, $uom) !== false){ // sort each element in the best order to execute the rest of the function foreach ($str_ele as $key => $element) { if (stripos($element, '/') !== false) { $x = stripos($element, '/'); $chk = substr($element, $x-1, 1); if (is_numeric($chk)) { $new_arr[0] = $element; } else { $new_arr[$pos] = $element; $pos++; } } } // do the math to get the qty/uom foreach ($new_arr as $key => $str) { echo $str."\n\n"; if (stripos($str, '/'.$uom) !== false) { $size = preg_replace('/[^0-9]/', '', $str); $qty_uom *= $size; break; } else { $size = preg_replace('/[^0-9]/', '', $str); $qty_uom *= $size; } } } $result['qty_uom'] = $qty_uom; print_r($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 25
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 25
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 24
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 24
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 112
Branch analysis from position: 49
2 jumps found. (Code = 77) Position 1 = 50, Position 2 = 81
Branch analysis from position: 50
2 jumps found. (Code = 78) Position 1 = 51, Position 2 = 81
Branch analysis from position: 51
2 jumps found. (Code = 43) Position 1 = 58, Position 2 = 80
Branch analysis from position: 58
2 jumps found. (Code = 43) Position 1 = 74, Position 2 = 77
Branch analysis from position: 74
1 jumps found. (Code = 42) Position 1 = 80
Branch analysis from position: 80
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
Branch analysis from position: 77
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
Branch analysis from position: 80
Branch analysis from position: 81
2 jumps found. (Code = 77) Position 1 = 83, Position 2 = 111
Branch analysis from position: 83
2 jumps found. (Code = 78) Position 1 = 84, Position 2 = 111
Branch analysis from position: 84
2 jumps found. (Code = 43) Position 1 = 94, Position 2 = 103
Branch analysis from position: 94
1 jumps found. (Code = 42) Position 1 = 111
Branch analysis from position: 111
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 103
1 jumps found. (Code = 42) Position 1 = 83
Branch analysis from position: 83
Branch analysis from position: 111
Branch analysis from position: 111
Branch analysis from position: 81
Branch analysis from position: 112
Branch analysis from position: 25
filename:       /in/SJoPF
function name:  (null)
number of ops:  118
compiled vars:  !0 = $desc, !1 = $uom, !2 = $keywords, !3 = $pkgstring, !4 = $result, !5 = $keyword, !6 = $key, !7 = $firstchar, !8 = $str_ele, !9 = $qty_uom, !10 = $new_arr, !11 = $pos, !12 = $element, !13 = $x, !14 = $chk, !15 = $str, !16 = $size
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, 'GLOVE+EXAM+BEST+TCH+ALOE+LTX+MED+100%2FBX+10BX%2FCS'
    3     1        ASSIGN                                                   !1, 'CS'
    4     2        INIT_FCALL                                               'explode'
          3        SEND_VAL                                                 '+'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $19     
          6        ASSIGN                                                   !2, $19
    5     7        ASSIGN                                                   !3, ''
    6     8        ASSIGN                                                   !4, <array>
    7     9      > FE_RESET_R                                       $23     !2, ->25
         10    > > FE_FETCH_R                                       ~24     $23, !5, ->25
         11    >   ASSIGN                                                   !6, ~24
    8    12        INIT_FCALL                                               'substr'
         13        SEND_VAR                                                 !5
         14        SEND_VAL                                                 0
         15        SEND_VAL                                                 1
         16        DO_ICALL                                         $26     
         17        ASSIGN                                                   !7, $26
    9    18        INIT_FCALL                                               'is_numeric'
         19        SEND_VAR                                                 !7
         20        DO_ICALL                                         $28     
         21      > JMPZ                                                     $28, ->24
   10    22    >   CONCAT                                           ~29     !5, '%2C'
         23        ASSIGN_OP                                     8          !3, ~29
    7    24    > > JMP                                                      ->10
         25    >   FE_FREE                                                  $23
   13    26        INIT_FCALL                                               'substr'
         27        SEND_VAR                                                 !3
         28        SEND_VAL                                                 0
         29        SEND_VAL                                                 -1
         30        DO_ICALL                                         $31     
         31        ASSIGN                                                   !3, $31
   14    32        ASSIGN_DIM                                               !4, 'pkgstring'
         33        OP_DATA                                                  !3
   16    34        INIT_FCALL                                               'explode'
         35        SEND_VAL                                                 '%2C'
         36        SEND_VAR                                                 !3
         37        DO_ICALL                                         $34     
         38        ASSIGN                                                   !8, $34
   17    39        ASSIGN                                                   !9, 1
   18    40        ASSIGN_DIM                                               !10, 0
         41        OP_DATA                                                  ''
   19    42        ASSIGN                                                   !11, 1
   20    43        INIT_FCALL                                               'stripos'
         44        SEND_VAR                                                 !3
         45        SEND_VAR                                                 !1
         46        DO_ICALL                                         $39     
         47        TYPE_CHECK                                  1018          $39
         48      > JMPZ                                                     ~40, ->112
   22    49    > > FE_RESET_R                                       $41     !8, ->81
         50    > > FE_FETCH_R                                       ~42     $41, !12, ->81
         51    >   ASSIGN                                                   !6, ~42
   23    52        INIT_FCALL                                               'stripos'
         53        SEND_VAR                                                 !12
         54        SEND_VAL                                                 '%2F'
         55        DO_ICALL                                         $44     
         56        TYPE_CHECK                                  1018          $44
         57      > JMPZ                                                     ~45, ->80
   24    58    >   INIT_FCALL                                               'stripos'
         59        SEND_VAR                                                 !12
         60        SEND_VAL                                                 '%2F'
         61        DO_ICALL                                         $46     
         62        ASSIGN                                                   !13, $46
   25    63        INIT_FCALL                                               'substr'
         64        SEND_VAR                                                 !12
         65        SUB                                              ~48     !13, 1
         66        SEND_VAL                                                 ~48
         67        SEND_VAL                                                 1
         68        DO_ICALL                                         $49     
         69        ASSIGN                                                   !14, $49
   26    70        INIT_FCALL                                               'is_numeric'
         71        SEND_VAR                                                 !14
         72        DO_ICALL                                         $51     
         73      > JMPZ                                                     $51, ->77
   27    74    >   ASSIGN_DIM                                               !10, 0
         75        OP_DATA                                                  !12
         76      > JMP                                                      ->80
   29    77    >   ASSIGN_DIM                                               !10, !11
         78        OP_DATA                                                  !12
   30    79        PRE_INC                                                  !11
   22    80    > > JMP                                                      ->50
         81    >   FE_FREE                                                  $41
   35    82      > FE_RESET_R                                       $55     !10, ->111
         83    > > FE_FETCH_R                                       ~56     $55, !15, ->111
         84    >   ASSIGN                                                   !6, ~56
   36    85        CONCAT                                           ~58     !15, '%0A%0A'
         86        ECHO                                                     ~58
   37    87        INIT_FCALL                                               'stripos'
         88        SEND_VAR                                                 !15
         89        CONCAT                                           ~59     '%2F', !1
         90        SEND_VAL                                                 ~59
         91        DO_ICALL                                         $60     
         92        TYPE_CHECK                                  1018          $60
         93      > JMPZ                                                     ~61, ->103
   38    94    >   INIT_FCALL                                               'preg_replace'
         95        SEND_VAL                                                 '%2F%5B%5E0-9%5D%2F'
         96        SEND_VAL                                                 ''
         97        SEND_VAR                                                 !15
         98        DO_ICALL                                         $62     
         99        ASSIGN                                                   !16, $62
   39   100        ASSIGN_OP                                     3          !9, !16
   40   101      > JMP                                                      ->111
        102*       JMP                                                      ->110
   42   103    >   INIT_FCALL                                               'preg_replace'
        104        SEND_VAL                                                 '%2F%5B%5E0-9%5D%2F'
        105        SEND_VAL                                                 ''
        106        SEND_VAR                                                 !15
        107        DO_ICALL                                         $65     
        108        ASSIGN                                                   !16, $65
   43   109        ASSIGN_OP                                     3          !9, !16
   35   110      > JMP                                                      ->83
        111    >   FE_FREE                                                  $55
   47   112    >   ASSIGN_DIM                                               !4, 'qty_uom'
        113        OP_DATA                                                  !9
   49   114        INIT_FCALL                                               'print_r'
        115        SEND_VAR                                                 !4
        116        DO_ICALL                                                 
        117      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.43 ms | 1400 KiB | 25 Q