3v4l.org

run code in 500+ 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 = 18
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 18
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 17
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
filename:       /in/DoimK
function name:  findRoute
number of ops:  22
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, ->18
          6    > > FE_FETCH_R                                                   $5, !2, ->18
   14     7    >   FRAMELESS_ICALL_3                preg_replace        ~6      '%2F%7B.%2A%3F%7D%2F', '%5B%5E%2F%5D%2B'
          8        OP_DATA                                                      !2
          9        CONCAT                                               ~7      '%7E%5E', ~6
         10        CONCAT                                               ~8      ~7, '%24%7E'
         11        ASSIGN                                                       !3, ~8
   15    12        FRAMELESS_ICALL_2                preg_match          ~10     !3, !1
         13      > JMPZ                                                         ~10, ->17
   16    14    >   VERIFY_RETURN_TYPE                                           !2
         15        FE_FREE                                                      $5
         16      > RETURN                                                       !2
   13    17    > > JMP                                                          ->6
         18    >   FE_FREE                                                      $5
   19    19      > RETURN                                                       null
   20    20*       VERIFY_RETURN_TYPE                                           
         21*     > RETURN                                                       null

End of function findroute

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
158.09 ms | 2137 KiB | 15 Q