3v4l.org

run code in 300+ PHP versions simultaneously
<?php $pathInfo = 'store/view/14342/galaxy-s10-lite-sm-g770-8gb'; $routes = [ 'store/{id}/{pid}' => ['home/store', ['id', 'exuo', 'pid']], 'store/{id}' => ['home/store', ['id']], 'store/view/{id}/{name}' => ['home/store', ['id', 'name']], // pathInfo should match this route ]; function findRoute(array $routes, string $pathInfo): ?string { foreach (array_keys($routes) as $routePath) { $pattern = '~^' . preg_replace('/{.*?}/', '[^/]+', $routePath) . '$~'; if (preg_match($pattern, $pathInfo)) { return $routePath; } } return null; } echo findRoute($routes, $pathInfo);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DoimK
function name:  (null)
number of ops:  8
compiled vars:  !0 = $pathInfo, !1 = $routes
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'store%2Fview%2F14342%2Fgalaxy-s10-lite-sm-g770-8gb'
    5     1        ASSIGN                                                   !1, <array>
   22     2        INIT_FCALL                                               'findroute'
          3        SEND_VAR                                                 !1
          4        SEND_VAR                                                 !0
          5        DO_FCALL                                      0  $4      
          6        ECHO                                                     $4
          7      > RETURN                                                   1

Function findroute:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 24
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 24
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 23
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/DoimK
function name:  findRoute
number of ops:  28
compiled vars:  !0 = $routes, !1 = $pathInfo, !2 = $routePath, !3 = $pattern
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   13     2        INIT_FCALL                                               'array_keys'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $4      
          5      > FE_RESET_R                                       $5      $4, ->24
          6    > > FE_FETCH_R                                               $5, !2, ->24
   14     7    >   INIT_FCALL                                               'preg_replace'
          8        SEND_VAL                                                 '%2F%7B.%2A%3F%7D%2F'
          9        SEND_VAL                                                 '%5B%5E%2F%5D%2B'
         10        SEND_VAR                                                 !2
         11        DO_ICALL                                         $6      
         12        CONCAT                                           ~7      '%7E%5E', $6
         13        CONCAT                                           ~8      ~7, '%24%7E'
         14        ASSIGN                                                   !3, ~8
   15    15        INIT_FCALL                                               'preg_match'
         16        SEND_VAR                                                 !3
         17        SEND_VAR                                                 !1
         18        DO_ICALL                                         $10     
         19      > JMPZ                                                     $10, ->23
   16    20    >   VERIFY_RETURN_TYPE                                       !2
         21        FE_FREE                                                  $5
         22      > RETURN                                                   !2
   13    23    > > JMP                                                      ->6
         24    >   FE_FREE                                                  $5
   19    25      > RETURN                                                   null
   20    26*       VERIFY_RETURN_TYPE                                       
         27*     > RETURN                                                   null

End of function findroute

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
218.36 ms | 1007 KiB | 17 Q