3v4l.org

run code in 300+ PHP versions simultaneously
<?php $tests = [ '28{8}17{7}15{9}19[1]', '28{8}17{7}15[1]', '28{8}17[1]', '28[1]', '28{8}17[1', ]; foreach($tests as $test) { if (!preg_match_all('~^\d+(?=.+\[\d+]$)|\G(?!^)(?:{\K\d+}\d+|\[\K\d(?=]$))~', $test, $m)) { echo "invalid input"; } else { var_export( [ 'id' => array_shift($m[0]), 'quantity' => array_pop($m[0]), 'options' => array_reduce( $m[0], function($result, $string) { [$key, $result[$key]] = explode('}', $string, 2); return $result; }, [] ) ] ); } echo "\n---\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 35
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 35
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
filename:       /in/9ENJl
function name:  (null)
number of ops:  37
compiled vars:  !0 = $tests, !1 = $test, !2 = $m
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   11     1      > FE_RESET_R                                       $4      !0, ->35
          2    > > FE_FETCH_R                                               $4, !1, ->35
   12     3    >   INIT_FCALL                                               'preg_match_all'
          4        SEND_VAL                                                 '%7E%5E%5Cd%2B%28%3F%3D.%2B%5C%5B%5Cd%2B%5D%24%29%7C%5CG%28%3F%21%5E%29%28%3F%3A%7B%5CK%5Cd%2B%7D%5Cd%2B%7C%5C%5B%5CK%5Cd%28%3F%3D%5D%24%29%29%7E'
          5        SEND_VAR                                                 !1
          6        SEND_REF                                                 !2
          7        DO_ICALL                                         $5      
          8        BOOL_NOT                                         ~6      $5
          9      > JMPZ                                                     ~6, ->12
   13    10    >   ECHO                                                     'invalid+input'
   12    11      > JMP                                                      ->33
   15    12    >   INIT_FCALL                                               'var_export'
   17    13        INIT_FCALL                                               'array_shift'
         14        FETCH_DIM_W                                      $7      !2, 0
         15        SEND_REF                                                 $7
         16        DO_ICALL                                         $8      
         17        INIT_ARRAY                                       ~9      $8, 'id'
   18    18        INIT_FCALL                                               'array_pop'
         19        FETCH_DIM_W                                      $10     !2, 0
         20        SEND_REF                                                 $10
         21        DO_ICALL                                         $11     
         22        ADD_ARRAY_ELEMENT                                ~9      $11, 'quantity'
   19    23        INIT_FCALL                                               'array_reduce'
   20    24        FETCH_DIM_R                                      ~12     !2, 0
         25        SEND_VAL                                                 ~12
   21    26        DECLARE_LAMBDA_FUNCTION                          ~13     [0]
   24    27        SEND_VAL                                                 ~13
   25    28        SEND_VAL                                                 <array>
   19    29        DO_ICALL                                         $14     
   25    30        ADD_ARRAY_ELEMENT                                ~9      $14, 'options'
         31        SEND_VAL                                                 ~9
   15    32        DO_ICALL                                                 
   30    33    >   ECHO                                                     '%0A---%0A'
   11    34      > JMP                                                      ->2
         35    >   FE_FREE                                                  $4
   31    36      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9ENJl
function name:  {closure}
number of ops:  15
compiled vars:  !0 = $result, !1 = $string, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   22     2        INIT_FCALL                                               'explode'
          3        SEND_VAL                                                 '%7D'
          4        SEND_VAR                                                 !1
          5        SEND_VAL                                                 2
          6        DO_ICALL                                         $3      
          7        FETCH_LIST_R                                     $4      $3, 0
          8        ASSIGN                                                   !2, $4
          9        FETCH_LIST_R                                     $6      $3, 1
         10        ASSIGN_DIM                                               !0, !2
         11        OP_DATA                                                  $6
         12        FREE                                                     $3
   23    13      > RETURN                                                   !0
   24    14*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
235.88 ms | 1010 KiB | 19 Q