3v4l.org

run code in 500+ PHP versions simultaneously
<?php $data = [ "localhost/my_system/users", "localhost/my_system/users/add_user", "localhost/my_system/users/by_letter/groups", "localhost/my_system/users/add_group"]; $url = "localhost/my_system/users/by_letter/s"; function getClosestURL($url, $data){ $matches = []; $explodedURL = explode("/", $url); foreach ($data as $match) { $explodedMatch = explode("/", $match); $matches[] = array_intersect($explodedMatch, $explodedURL); } return count(max($matches)) > 0 ? implode("/", max($matches)) : false; } var_dump(getClosestURL($url, $data)); //returns localhost/my_system/users/by_letter var_dump(getClosestURL("local/no/match", $data)); //returns false
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QIsIt
function name:  (null)
number of ops:  17
compiled vars:  !0 = $data, !1 = $url
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                       !0, <array>
    6     1        ASSIGN                                                       !1, 'localhost%2Fmy_system%2Fusers%2Fby_letter%2Fs'
   17     2        INIT_FCALL                                                   'var_dump'
          3        INIT_FCALL                                                   'getclosesturl'
          4        SEND_VAR                                                     !1
          5        SEND_VAR                                                     !0
          6        DO_FCALL                                          0  $4      
          7        SEND_VAR                                                     $4
          8        DO_ICALL                                                     
   18     9        INIT_FCALL                                                   'var_dump'
         10        INIT_FCALL                                                   'getclosesturl'
         11        SEND_VAL                                                     'local%2Fno%2Fmatch'
         12        SEND_VAR                                                     !0
         13        DO_FCALL                                          0  $6      
         14        SEND_VAR                                                     $6
         15        DO_ICALL                                                     
         16      > RETURN                                                       1

Function getclosesturl:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 22
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 22
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 35
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/QIsIt
function name:  getClosestURL
number of ops:  38
compiled vars:  !0 = $url, !1 = $data, !2 = $matches, !3 = $explodedURL, !4 = $match, !5 = $explodedMatch
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    7     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
    8     2        ASSIGN                                                       !2, <array>
    9     3        INIT_FCALL                                                   'explode'
          4        SEND_VAL                                                     '%2F'
          5        SEND_VAR                                                     !0
          6        DO_ICALL                                             $7      
          7        ASSIGN                                                       !3, $7
   10     8      > FE_RESET_R                                           $9      !1, ->22
          9    > > FE_FETCH_R                                                   $9, !4, ->22
   11    10    >   INIT_FCALL                                                   'explode'
         11        SEND_VAL                                                     '%2F'
         12        SEND_VAR                                                     !4
         13        DO_ICALL                                             $10     
         14        ASSIGN                                                       !5, $10
   12    15        INIT_FCALL                                                   'array_intersect'
         16        SEND_VAR                                                     !5
         17        SEND_VAR                                                     !3
         18        DO_ICALL                                             $13     
         19        ASSIGN_DIM                                                   !2
         20        OP_DATA                                                      $13
   10    21      > JMP                                                          ->9
         22    >   FE_FREE                                                      $9
   14    23        INIT_FCALL                                                   'max'
         24        SEND_VAR                                                     !2
         25        DO_ICALL                                             $14     
         26        COUNT                                                ~15     $14
         27        IS_SMALLER                                                   0, ~15
         28      > JMPZ                                                         ~16, ->35
         29    >   INIT_FCALL                                                   'max'
         30        SEND_VAR                                                     !2
         31        DO_ICALL                                             $17     
         32        FRAMELESS_ICALL_2                implode             ~18     '%2F', $17
         33        QM_ASSIGN                                            ~19     ~18
         34      > JMP                                                          ->36
         35    >   QM_ASSIGN                                            ~19     <false>
         36    > > RETURN                                                       ~19
   15    37*     > RETURN                                                       null

End of function getclosesturl

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
173.85 ms | 3348 KiB | 20 Q