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) { echo "$name\t\t"; $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 echo "\n"; var_dump( $current, $matches+[1,2] );
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 23
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 23
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 22
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
2 jumps found. (Code = 77) Position 1 = 28, Position 2 = 35
Branch analysis from position: 28
2 jumps found. (Code = 78) Position 1 = 29, Position 2 = 35
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 34
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
Branch analysis from position: 34
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 23
Branch analysis from position: 23
filename:       /in/ZPPad
function name:  (null)
number of ops:  43
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, ->23
          4    > > FE_FETCH_R                                       ~11     $10, !3, ->23
          5    >   ASSIGN                                                   !4, ~11
   34     6        NOP                                                      
          7        FAST_CONCAT                                      ~13     !4, '%09%09'
          8        ECHO                                                     ~13
   35     9        ASSIGN                                                   !5, <array>
   36    10        INIT_FCALL                                               'preg_match'
         11        FETCH_DIM_R                                      ~15     !3, 'pattern'
         12        SEND_VAL                                                 ~15
         13        SEND_VAR                                                 !0
         14        SEND_REF                                                 !5
         15        DO_ICALL                                         $16     
         16      > JMPZ                                                     $16, ->22
   37    17    >   ASSIGN                                                   !2, !4
   38    18        FETCH_DIM_R                                      ~18     !3, 'default'
         19        ADD                                              ~19     !5, ~18
         20        ASSIGN                                                   !5, ~19
   39    21      > JMP                                                      ->23
   33    22    > > JMP                                                      ->4
         23    >   FE_FREE                                                  $10
   45    24        INIT_FCALL                                               'array_keys'
         25        SEND_VAR                                                 !5
         26        DO_ICALL                                         $21     
         27      > FE_RESET_R                                       $22     $21, ->35
         28    > > FE_FETCH_R                                               $22, !6, ->35
   46    29    >   INIT_FCALL                                               'is_numeric'
         30        SEND_VAR                                                 !6
         31        DO_ICALL                                         $23     
         32      > JMPZ                                                     $23, ->34
   47    33    >   UNSET_DIM                                                !5, !6
   45    34    > > JMP                                                      ->28
         35    >   FE_FREE                                                  $22
   53    36        ECHO                                                     '%0A'
   54    37        INIT_FCALL                                               'var_dump'
         38        SEND_VAR                                                 !2
         39        ADD                                              ~24     !5, <array>
         40        SEND_VAL                                                 ~24
         41        DO_ICALL                                                 
         42      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.48 ms | 1400 KiB | 21 Q