3v4l.org

run code in 300+ PHP versions simultaneously
<?php $dirs = ['/chris', '/chris/usa', '/david', '/', '/chris/canada/2022', '/david/uk']; $current_path = "/chris"; $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 = str_replace($current_path . '/', '', $dir); // Remove '/chris/' if any. if (empty($relPath)) { continue; } // Get the first dir of this path [$dir2] = explode('/', $relPath); // Store and add removed slash $sub_dirs[] = '/' . $dir2; } var_export($sub_dirs);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 34
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 34
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 13
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 23
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
filename:       /in/4hNE5
function name:  (null)
number of ops:  39
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, '%2Fchris'
    7     2        ASSIGN                                                   !2, <array>
    8     3      > FE_RESET_R                                       $9      !0, ->34
          4    > > FE_FETCH_R                                               $9, !3, ->34
   11     5    >   INIT_FCALL                                               'strpos'
          6        SEND_VAR                                                 !3
          7        CONCAT                                           ~10     !1, '%2F'
          8        SEND_VAL                                                 ~10
          9        DO_ICALL                                         $11     
         10        TYPE_CHECK                                    4          $11
         11      > JMPZ                                                     ~12, ->13
   12    12    > > JMP                                                      ->4
   16    13    >   INIT_FCALL                                               'str_replace'
         14        CONCAT                                           ~13     !1, '%2F'
         15        SEND_VAL                                                 ~13
         16        SEND_VAL                                                 ''
         17        SEND_VAR                                                 !3
         18        DO_ICALL                                         $14     
         19        ASSIGN                                                   !4, $14
   19    20        ISSET_ISEMPTY_CV                                         !4
         21      > JMPZ                                                     ~16, ->23
   20    22    > > JMP                                                      ->4
   24    23    >   INIT_FCALL                                               'explode'
         24        SEND_VAL                                                 '%2F'
         25        SEND_VAR                                                 !4
         26        DO_ICALL                                         $17     
         27        FETCH_LIST_R                                     $18     $17, 0
         28        ASSIGN                                                   !5, $18
         29        FREE                                                     $17
   27    30        CONCAT                                           ~21     '%2F', !5
         31        ASSIGN_DIM                                               !2
         32        OP_DATA                                                  ~21
    8    33      > JMP                                                      ->4
         34    >   FE_FREE                                                  $9
   30    35        INIT_FCALL                                               'var_export'
         36        SEND_VAR                                                 !2
         37        DO_ICALL                                                 
         38      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.65 ms | 1018 KiB | 17 Q