3v4l.org

run code in 300+ PHP versions simultaneously
<?php $dirs = ['/chris', '/chris/usa', '/david', '/', '/chris/canada/2022', '/david/uk']; $current_path = "/"; $sub_dirs = []; foreach($dirs as $dir) { // Ensure $dir starts with path + '/' (sub dir of $current_path) if (strpos($dir, $current_path) === false) { continue; } // Get the relative path from $current_path $relPath = substr($dir, strlen($current_path)); // Get the first dir of this path [$dir2] = explode('/', ltrim($relPath,'/')); if (empty($dir2)) { continue; } // Store and add removed slash $sub_dirs[] = '/' . $dir2; } var_export(array_unique($sub_dirs));
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 36
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 36
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 12
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 32
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
filename:       /in/BYnlW
function name:  (null)
number of ops:  44
compiled vars:  !0 = $dirs, !1 = $current_path, !2 = $sub_dirs, !3 = $dir, !4 = $relPath, !5 = $dir2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    5     1        ASSIGN                                                   !1, '%2F'
    7     2        ASSIGN                                                   !2, <array>
    8     3      > FE_RESET_R                                       $9      !0, ->36
          4    > > FE_FETCH_R                                               $9, !3, ->36
   11     5    >   INIT_FCALL                                               'strpos'
          6        SEND_VAR                                                 !3
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                         $10     
          9        TYPE_CHECK                                    4          $10
         10      > JMPZ                                                     ~11, ->12
   12    11    > > JMP                                                      ->4
   16    12    >   INIT_FCALL                                               'substr'
         13        SEND_VAR                                                 !3
         14        STRLEN                                           ~12     !1
         15        SEND_VAL                                                 ~12
         16        DO_ICALL                                         $13     
         17        ASSIGN                                                   !4, $13
   19    18        INIT_FCALL                                               'explode'
         19        SEND_VAL                                                 '%2F'
         20        INIT_FCALL                                               'ltrim'
         21        SEND_VAR                                                 !4
         22        SEND_VAL                                                 '%2F'
         23        DO_ICALL                                         $15     
         24        SEND_VAR                                                 $15
         25        DO_ICALL                                         $16     
         26        FETCH_LIST_R                                     $17     $16, 0
         27        ASSIGN                                                   !5, $17
         28        FREE                                                     $16
   21    29        ISSET_ISEMPTY_CV                                         !5
         30      > JMPZ                                                     ~19, ->32
   22    31    > > JMP                                                      ->4
   26    32    >   CONCAT                                           ~21     '%2F', !5
         33        ASSIGN_DIM                                               !2
         34        OP_DATA                                                  ~21
    8    35      > JMP                                                      ->4
         36    >   FE_FREE                                                  $9
   29    37        INIT_FCALL                                               'var_export'
         38        INIT_FCALL                                               'array_unique'
         39        SEND_VAR                                                 !2
         40        DO_ICALL                                         $22     
         41        SEND_VAR                                                 $22
         42        DO_ICALL                                                 
         43      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
206.41 ms | 1021 KiB | 19 Q