3v4l.org

run code in 300+ PHP versions simultaneously
<?php $uri = '/blah/bah/blah/this-is-the-slug/'; function uriData($uri) { $parts = explode('/', $uri); // the uri ends with a '/', so we don't need the last element // && array indexs start at 0; so idx-1 = actual key_id $slug = $parts[(count($parts)-2)]; $cat_path = array_slice($parts, 0, (count($parts)-3), true); return [implode('/', $cat_path), $slug]; } var_dump(uriData($uri));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hCheC
function name:  (null)
number of ops:  8
compiled vars:  !0 = $uri
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%2Fblah%2Fbah%2Fblah%2Fthis-is-the-slug%2F'
   13     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL                                               'uridata'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Function uridata:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hCheC
function name:  uriData
number of ops:  27
compiled vars:  !0 = $uri, !1 = $parts, !2 = $slug, !3 = $cat_path
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    5     1        INIT_FCALL                                               'explode'
          2        SEND_VAL                                                 '%2F'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $4      
          5        ASSIGN                                                   !1, $4
    8     6        COUNT                                            ~6      !1
          7        SUB                                              ~7      ~6, 2
          8        FETCH_DIM_R                                      ~8      !1, ~7
          9        ASSIGN                                                   !2, ~8
    9    10        INIT_FCALL                                               'array_slice'
         11        SEND_VAR                                                 !1
         12        SEND_VAL                                                 0
         13        COUNT                                            ~10     !1
         14        SUB                                              ~11     ~10, 3
         15        SEND_VAL                                                 ~11
         16        SEND_VAL                                                 <true>
         17        DO_ICALL                                         $12     
         18        ASSIGN                                                   !3, $12
   10    19        INIT_FCALL                                               'implode'
         20        SEND_VAL                                                 '%2F'
         21        SEND_VAR                                                 !3
         22        DO_ICALL                                         $14     
         23        INIT_ARRAY                                       ~15     $14
         24        ADD_ARRAY_ELEMENT                                ~15     !2
         25      > RETURN                                                   ~15
   11    26*     > RETURN                                                   null

End of function uridata

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.92 ms | 1399 KiB | 22 Q