3v4l.org

run code in 300+ 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 = 32
Branch analysis from position: 25
2 jumps found. (Code = 78) Position 1 = 26, Position 2 = 32
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 31
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 31
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
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:  38
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, ->32
         25    > > FE_FETCH_R                                               $21, !6, ->32
   45    26    >   INIT_FCALL                                               'is_numeric'
         27        SEND_VAR                                                 !6
         28        DO_ICALL                                         $22     
         29      > JMPZ                                                     $22, ->31
   46    30    >   UNSET_DIM                                                !5, !6
   44    31    > > JMP                                                      ->25
         32    >   FE_FREE                                                  $21
   52    33        INIT_FCALL                                               'var_dump'
         34        SEND_VAR                                                 !2
         35        SEND_VAR                                                 !5
         36        DO_ICALL                                                 
         37      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.28 ms | 1467 KiB | 17 Q