3v4l.org

run code in 300+ PHP versions simultaneously
<?php $routes = [ 'primary' => [ 'pattern' => '#/(?P<resource>[^/\\\\.,;?\n]+)/foobar#', 'default' => [ 'action' => 'standard', ], ], 'secundary' => [ 'pattern' => '#^/(?P<id>[0-9]+)$#', 'default' => [ 'resource' => 'catalog', 'action' => 'view', ] ], 'fallback' => [ 'pattern' => '#^$#', 'default' => [ 'resource' => 'main', 'action' => 'landing', ], ], ]; $url = '/foobar/12345'; $current = null; foreach ($routes as $name => $route) { $matches = []; if ( preg_match( $route['pattern'], $url, $matches ) ) { $current = $name; $matches = $matches + $route['default']; break; } } var_dump( $name, $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
1 jumps found. (Code = 62) Position 1 = -2
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/R5jZe
function name:  (null)
number of ops:  26
compiled vars:  !0 = $routes, !1 = $url, !2 = $current, !3 = $route, !4 = $name, !5 = $matches
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   27     1        ASSIGN                                                   !1, '%2Ffoobar%2F12345'
   28     2        ASSIGN                                                   !2, null
   30     3      > FE_RESET_R                                       $9      !0, ->20
          4    > > FE_FETCH_R                                       ~10     $9, !3, ->20
          5    >   ASSIGN                                                   !4, ~10
   31     6        ASSIGN                                                   !5, <array>
   32     7        INIT_FCALL                                               'preg_match'
          8        FETCH_DIM_R                                      ~13     !3, 'pattern'
          9        SEND_VAL                                                 ~13
         10        SEND_VAR                                                 !1
         11        SEND_REF                                                 !5
         12        DO_ICALL                                         $14     
         13      > JMPZ                                                     $14, ->19
   33    14    >   ASSIGN                                                   !2, !4
   34    15        FETCH_DIM_R                                      ~16     !3, 'default'
         16        ADD                                              ~17     !5, ~16
         17        ASSIGN                                                   !5, ~17
   35    18      > JMP                                                      ->20
   30    19    > > JMP                                                      ->4
         20    >   FE_FREE                                                  $9
   40    21        INIT_FCALL                                               'var_dump'
         22        SEND_VAR                                                 !4
         23        SEND_VAR                                                 !5
         24        DO_ICALL                                                 
         25      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.35 ms | 1388 KiB | 17 Q