3v4l.org

run code in 500+ PHP versions simultaneously
<?php // CHANGE THIS $url = '/12345/product'; $routes = [ 'primary' => [ 'pattern' => '#/(?P<resource>[^/\\\\.,;?\n]+)/foobar#', 'default' => [ 'action' => 'standard', ], ], 'secundary' => [ 'pattern' => '#^/(?P<id>[0-9]+)(?:/(?P<resource>[^/\\\\.,;?\n]+)(?:/(?P<action>[^/\\\\.,;?\n]+))?)?$#', 'default' => [ 'resource' => 'catalog', 'action' => 'view', ] ], 'fallback' => [ 'pattern' => '#^.*$#', 'default' => [ 'resource' => 'main', 'action' => 'landing', ], ], ]; $current = null; // matching the route foreach ($routes as $name => $route) { $matches = []; if ( preg_match( $route['pattern'], $url, $matches ) ) { $current = $name; $matches = $matches + $route['default']; break; } } // cleaning up results foreach ( array_keys($matches) as $key ) { if ( is_numeric($key) ) { unset( $matches[$key] ); } } // view results var_dump( $current, $matches );
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 20
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 20
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 19
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
2 jumps found. (Code = 77) Position 1 = 25, Position 2 = 30
Branch analysis from position: 25
2 jumps found. (Code = 78) Position 1 = 26, Position 2 = 30
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 29
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 29
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 20
Branch analysis from position: 20
filename:       /in/T7i3l
function name:  (null)
number of ops:  36
compiled vars:  !0 = $url, !1 = $routes, !2 = $current, !3 = $route, !4 = $name, !5 = $matches, !6 = $key
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                       !0, '%2F12345%2Fproduct'
    7     1        ASSIGN                                                       !1, <array>
   30     2        ASSIGN                                                       !2, null
   33     3      > FE_RESET_R                                           $10     !1, ->20
          4    > > FE_FETCH_R                                           ~11     $10, !3, ->20
          5    >   ASSIGN                                                       !4, ~11
   34     6        ASSIGN                                                       !5, <array>
   35     7        INIT_FCALL                                                   'preg_match'
          8        FETCH_DIM_R                                          ~14     !3, 'pattern'
          9        SEND_VAL                                                     ~14
         10        SEND_VAR                                                     !0
         11        SEND_REF                                                     !5
         12        DO_ICALL                                             $15     
         13      > JMPZ                                                         $15, ->19
   36    14    >   ASSIGN                                                       !2, !4
   37    15        FETCH_DIM_R                                          ~17     !3, 'default'
         16        ADD                                                  ~18     !5, ~17
         17        ASSIGN                                                       !5, ~18
   38    18      > JMP                                                          ->20
   33    19    > > JMP                                                          ->4
         20    >   FE_FREE                                                      $10
   44    21        INIT_FCALL                                                   'array_keys'
         22        SEND_VAR                                                     !5
         23        DO_ICALL                                             $20     
         24      > FE_RESET_R                                           $21     $20, ->30
         25    > > FE_FETCH_R                                                   $21, !6, ->30
   45    26    >   FRAMELESS_ICALL_1                is_numeric          ~22     !6
         27      > JMPZ                                                         ~22, ->29
   46    28    >   UNSET_DIM                                                    !5, !6
   44    29    > > JMP                                                          ->25
         30    >   FE_FREE                                                      $21
   52    31        INIT_FCALL                                                   'var_dump'
         32        SEND_VAR                                                     !2
         33        SEND_VAR                                                     !5
         34        DO_ICALL                                                     
         35      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
165.65 ms | 3335 KiB | 16 Q