3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = 'My Interests:379{Commercial:0,Consumer:1,Wholesale Reseller:2},Test Group:1234{Test One:1,Test 2:2}'; $regex = '(?<group_name>[a-zA-Z0-9 _]+):(?<group_id>[0-9]+)(?={)|(?<=[{,])(?<option_name>[^:]+):(?<option_id>[^,}]+)(?=[,}])'; preg_match_all("/$regex/", $string, $matches); //print_r($matches); $groups = array_combine(array_filter($matches['group_name']), array_filter($matches['group_id'], function ($v) { return $v !== '';})); $options = array_combine(array_filter($matches['option_name']), array_filter($matches['option_id'], function ($v) { return $v !== '';})); print_r($groups); print_r($options); $output = array(); for ($i = 0; $i < count($matches['group_name']); $i++) { if ($matches['group_name'][$i] != '') { // new group $this_group = $matches['group_name'][$i]; $output[$this_group] = array('id' => $matches['group_id'][$i]); } else { // option for this group $output[$this_group]['options'][$matches['option_name'][$i]] = $matches['option_id'][$i]; } } print_r($output); $output = array(); $this_group = -1; for ($i = 0; $i < count($matches['group_name']); $i++) { if ($matches['group_name'][$i] != '') { // new group $this_group++; $output[$this_group] = array('name' => $matches['group_name'][$i], 'id' => $matches['group_id'][$i]); } else { // option for this group $output[$this_group]['options'][$matches['option_name'][$i]] = $matches['option_id'][$i]; } } print_r($output);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 71
Branch analysis from position: 71
2 jumps found. (Code = 44) Position 1 = 75, Position 2 = 49
Branch analysis from position: 75
1 jumps found. (Code = 42) Position 1 = 105
Branch analysis from position: 105
2 jumps found. (Code = 44) Position 1 = 109, Position 2 = 82
Branch analysis from position: 109
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 82
2 jumps found. (Code = 43) Position 1 = 86, Position 2 = 96
Branch analysis from position: 86
1 jumps found. (Code = 42) Position 1 = 104
Branch analysis from position: 104
2 jumps found. (Code = 44) Position 1 = 109, Position 2 = 82
Branch analysis from position: 109
Branch analysis from position: 82
Branch analysis from position: 96
2 jumps found. (Code = 44) Position 1 = 109, Position 2 = 82
Branch analysis from position: 109
Branch analysis from position: 82
Branch analysis from position: 49
2 jumps found. (Code = 43) Position 1 = 53, Position 2 = 62
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 70
Branch analysis from position: 70
2 jumps found. (Code = 44) Position 1 = 75, Position 2 = 49
Branch analysis from position: 75
Branch analysis from position: 49
Branch analysis from position: 62
2 jumps found. (Code = 44) Position 1 = 75, Position 2 = 49
Branch analysis from position: 75
Branch analysis from position: 49
filename:       /in/u97Im
function name:  (null)
number of ops:  113
compiled vars:  !0 = $string, !1 = $regex, !2 = $matches, !3 = $groups, !4 = $options, !5 = $output, !6 = $i, !7 = $this_group
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, 'My+Interests%3A379%7BCommercial%3A0%2CConsumer%3A1%2CWholesale+Reseller%3A2%7D%2CTest+Group%3A1234%7BTest+One%3A1%2CTest+2%3A2%7D'
    3     1        ASSIGN                                                   !1, '%28%3F%3Cgroup_name%3E%5Ba-zA-Z0-9+_%5D%2B%29%3A%28%3F%3Cgroup_id%3E%5B0-9%5D%2B%29%28%3F%3D%7B%29%7C%28%3F%3C%3D%5B%7B%2C%5D%29%28%3F%3Coption_name%3E%5B%5E%3A%5D%2B%29%3A%28%3F%3Coption_id%3E%5B%5E%2C%7D%5D%2B%29%28%3F%3D%5B%2C%7D%5D%29'
    4     2        INIT_FCALL                                               'preg_match_all'
          3        ROPE_INIT                                     3  ~11     '%2F'
          4        ROPE_ADD                                      1  ~11     ~11, !1
          5        ROPE_END                                      2  ~10     ~11, '%2F'
          6        SEND_VAL                                                 ~10
          7        SEND_VAR                                                 !0
          8        SEND_REF                                                 !2
          9        DO_ICALL                                                 
    6    10        INIT_FCALL                                               'array_combine'
         11        INIT_FCALL                                               'array_filter'
         12        FETCH_DIM_R                                      ~14     !2, 'group_name'
         13        SEND_VAL                                                 ~14
         14        DO_ICALL                                         $15     
         15        SEND_VAR                                                 $15
         16        INIT_FCALL                                               'array_filter'
         17        FETCH_DIM_R                                      ~16     !2, 'group_id'
         18        SEND_VAL                                                 ~16
         19        DECLARE_LAMBDA_FUNCTION                          ~17     [0]
         20        SEND_VAL                                                 ~17
         21        DO_ICALL                                         $18     
         22        SEND_VAR                                                 $18
         23        DO_ICALL                                         $19     
         24        ASSIGN                                                   !3, $19
    7    25        INIT_FCALL                                               'array_combine'
         26        INIT_FCALL                                               'array_filter'
         27        FETCH_DIM_R                                      ~21     !2, 'option_name'
         28        SEND_VAL                                                 ~21
         29        DO_ICALL                                         $22     
         30        SEND_VAR                                                 $22
         31        INIT_FCALL                                               'array_filter'
         32        FETCH_DIM_R                                      ~23     !2, 'option_id'
         33        SEND_VAL                                                 ~23
         34        DECLARE_LAMBDA_FUNCTION                          ~24     [1]
         35        SEND_VAL                                                 ~24
         36        DO_ICALL                                         $25     
         37        SEND_VAR                                                 $25
         38        DO_ICALL                                         $26     
         39        ASSIGN                                                   !4, $26
    8    40        INIT_FCALL                                               'print_r'
         41        SEND_VAR                                                 !3
         42        DO_ICALL                                                 
    9    43        INIT_FCALL                                               'print_r'
         44        SEND_VAR                                                 !4
         45        DO_ICALL                                                 
   10    46        ASSIGN                                                   !5, <array>
   11    47        ASSIGN                                                   !6, 0
         48      > JMP                                                      ->71
   12    49    >   FETCH_DIM_R                                      ~32     !2, 'group_name'
         50        FETCH_DIM_R                                      ~33     ~32, !6
         51        IS_NOT_EQUAL                                             ~33, ''
         52      > JMPZ                                                     ~34, ->62
   14    53    >   FETCH_DIM_R                                      ~35     !2, 'group_name'
         54        FETCH_DIM_R                                      ~36     ~35, !6
         55        ASSIGN                                                   !7, ~36
   15    56        FETCH_DIM_R                                      ~39     !2, 'group_id'
         57        FETCH_DIM_R                                      ~40     ~39, !6
         58        INIT_ARRAY                                       ~41     ~40, 'id'
         59        ASSIGN_DIM                                               !5, !7
         60        OP_DATA                                                  ~41
   12    61      > JMP                                                      ->70
   19    62    >   FETCH_DIM_R                                      ~44     !2, 'option_name'
         63        FETCH_DIM_R                                      ~45     ~44, !6
         64        FETCH_DIM_R                                      ~47     !2, 'option_id'
         65        FETCH_DIM_R                                      ~48     ~47, !6
         66        FETCH_DIM_W                                      $42     !5, !7
         67        FETCH_DIM_W                                      $43     $42, 'options'
         68        ASSIGN_DIM                                               $43, ~45
         69        OP_DATA                                                  ~48
   11    70    >   PRE_INC                                                  !6
         71    >   FETCH_DIM_R                                      ~50     !2, 'group_name'
         72        COUNT                                            ~51     ~50
         73        IS_SMALLER                                               !6, ~51
         74      > JMPNZ                                                    ~52, ->49
   22    75    >   INIT_FCALL                                               'print_r'
         76        SEND_VAR                                                 !5
         77        DO_ICALL                                                 
   23    78        ASSIGN                                                   !5, <array>
   24    79        ASSIGN                                                   !7, -1
   25    80        ASSIGN                                                   !6, 0
         81      > JMP                                                      ->105
   26    82    >   FETCH_DIM_R                                      ~57     !2, 'group_name'
         83        FETCH_DIM_R                                      ~58     ~57, !6
         84        IS_NOT_EQUAL                                             ~58, ''
         85      > JMPZ                                                     ~59, ->96
   28    86    >   PRE_INC                                                  !7
   29    87        FETCH_DIM_R                                      ~62     !2, 'group_name'
         88        FETCH_DIM_R                                      ~63     ~62, !6
         89        INIT_ARRAY                                       ~64     ~63, 'name'
         90        FETCH_DIM_R                                      ~65     !2, 'group_id'
         91        FETCH_DIM_R                                      ~66     ~65, !6
         92        ADD_ARRAY_ELEMENT                                ~64     ~66, 'id'
         93        ASSIGN_DIM                                               !5, !7
         94        OP_DATA                                                  ~64
   26    95      > JMP                                                      ->104
   33    96    >   FETCH_DIM_R                                      ~69     !2, 'option_name'
         97        FETCH_DIM_R                                      ~70     ~69, !6
         98        FETCH_DIM_R                                      ~72     !2, 'option_id'
         99        FETCH_DIM_R                                      ~73     ~72, !6
        100        FETCH_DIM_W                                      $67     !5, !7
        101        FETCH_DIM_W                                      $68     $67, 'options'
        102        ASSIGN_DIM                                               $68, ~70
        103        OP_DATA                                                  ~73
   25   104    >   PRE_INC                                                  !6
        105    >   FETCH_DIM_R                                      ~75     !2, 'group_name'
        106        COUNT                                            ~76     ~75
        107        IS_SMALLER                                               !6, ~76
        108      > JMPNZ                                                    ~77, ->82
   36   109    >   INIT_FCALL                                               'print_r'
        110        SEND_VAR                                                 !5
        111        DO_ICALL                                                 
        112      > 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/u97Im
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        IS_NOT_IDENTICAL                                 ~1      !0, ''
          2      > RETURN                                                   ~1
          3*     > RETURN                                                   null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/u97Im
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        IS_NOT_IDENTICAL                                 ~1      !0, ''
          2      > RETURN                                                   ~1
          3*     > RETURN                                                   null

End of Dynamic Function 1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
174.78 ms | 1453 KiB | 17 Q