3v4l.org

run code in 300+ PHP versions simultaneously
<?php echo getcwd();exit; function dirToArray1($dir) { $result = array(); $cdir = scandir($dir); foreach ($cdir as $key => $value) { if (!in_array($value,array(".",".."))) { if (is_dir($dir . DIRECTORY_SEPARATOR . $value)){ $result[$value] = dirToArray1($dir . DIRECTORY_SEPARATOR . $value); } else { $result[] = $value; } } } return $result; } function dirToArray2($dir) { $arr = []; $obj = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::CHILD_FIRST); foreach ($obj as $info) { if (in_array($info->getFilename(), ['.', '..'])) continue; $path = $info->isDir() ? [$info->getFilename() => []] : [$info->getFilename()]; for ($depth = $obj->getDepth() - 1; $depth >= 0; $depth--) { $path = [$obj->getSubIterator($depth)->current()->getFilename() => $path]; } $arr = array_merge_recursive($arr, $path); } return $arr; } foreach (['1', '2'] as $k) { $t = "t$k"; $d = "d$k"; $$t = microtime(true); $func = "dirToArray$k"; $$d = $func("/tmp"); $$t = $$t - microtime(true); echo "$func needed $$t time\n"; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 79) Position 1 = -2
filename:       /in/VQAE4
function name:  (null)
number of ops:  40
compiled vars:  !0 = $k, !1 = $t, !2 = $d, !3 = $func
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'getcwd'
          1        DO_ICALL                                         $4      
          2        ECHO                                                     $4
          3      > EXIT                                                     
   34     4*       FE_RESET_R                                       $5      <array>, ->38
          5*       FE_FETCH_R                                               $5, !0, ->38
   35     6*       NOP                                                      
          7*       FAST_CONCAT                                      ~6      't', !0
          8*       ASSIGN                                                   !1, ~6
   36     9*       NOP                                                      
         10*       FAST_CONCAT                                      ~8      'd', !0
         11*       ASSIGN                                                   !2, ~8
   37    12*       INIT_FCALL                                               'microtime'
         13*       SEND_VAL                                                 <true>
         14*       DO_ICALL                                         $11     
         15*       FETCH_W                      local               $10     !1
         16*       ASSIGN                                                   $10, $11
   38    17*       NOP                                                      
         18*       FAST_CONCAT                                      ~13     'dirToArray', !0
         19*       ASSIGN                                                   !3, ~13
   39    20*       INIT_DYNAMIC_CALL                                        !3
         21*       SEND_VAL_EX                                              '%2Ftmp'
         22*       DO_FCALL                                      0  $16     
         23*       FETCH_W                      local               $15     !2
         24*       ASSIGN                                                   $15, $16
   40    25*       FETCH_R                      local               ~19     !1
         26*       INIT_FCALL                                               'microtime'
         27*       SEND_VAL                                                 <true>
         28*       DO_ICALL                                         $20     
         29*       SUB                                              ~21     ~19, $20
         30*       FETCH_W                      local               $18     !1
         31*       ASSIGN                                                   $18, ~21
   41    32*       ROPE_INIT                                     4  ~24     !3
         33*       ROPE_ADD                                      1  ~24     ~24, '+needed+%24'
         34*       ROPE_ADD                                      2  ~24     ~24, !1
         35*       ROPE_END                                      3  ~23     ~24, '+time%0A'
         36*       ECHO                                                     ~23
   34    37*       JMP                                                      ->5
         38*       FE_FREE                                                  $5
   42    39*     > RETURN                                                   1

Function dirtoarray1:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 29
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 29
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 28
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 26
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 28
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
filename:       /in/VQAE4
function name:  dirToArray1
number of ops:  32
compiled vars:  !0 = $dir, !1 = $result, !2 = $cdir, !3 = $value, !4 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
    6     1        ASSIGN                                                   !1, <array>
    7     2        INIT_FCALL                                               'scandir'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $6      
          5        ASSIGN                                                   !2, $6
    8     6      > FE_RESET_R                                       $8      !2, ->29
          7    > > FE_FETCH_R                                       ~9      $8, !3, ->29
          8    >   ASSIGN                                                   !4, ~9
    9     9        IN_ARRAY                                         ~11     !3, <array>
         10        BOOL_NOT                                         ~12     ~11
         11      > JMPZ                                                     ~12, ->28
   10    12    >   INIT_FCALL                                               'is_dir'
         13        CONCAT                                           ~13     !0, '%2F'
         14        CONCAT                                           ~14     ~13, !3
         15        SEND_VAL                                                 ~14
         16        DO_ICALL                                         $15     
         17      > JMPZ                                                     $15, ->26
   11    18    >   INIT_FCALL_BY_NAME                                       'dirToArray1'
         19        CONCAT                                           ~17     !0, '%2F'
         20        CONCAT                                           ~18     ~17, !3
         21        SEND_VAL_EX                                              ~18
         22        DO_FCALL                                      0  $19     
         23        ASSIGN_DIM                                               !1, !3
         24        OP_DATA                                                  $19
         25      > JMP                                                      ->28
   13    26    >   ASSIGN_DIM                                               !1
         27        OP_DATA                                                  !3
    8    28    > > JMP                                                      ->7
         29    >   FE_FREE                                                  $8
   17    30      > RETURN                                                   !1
   18    31*     > RETURN                                                   null

End of function dirtoarray1

Function dirtoarray2:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 53
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 53
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 17
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 25
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
2 jumps found. (Code = 44) Position 1 = 47, Position 2 = 35
Branch analysis from position: 47
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 35
2 jumps found. (Code = 44) Position 1 = 47, Position 2 = 35
Branch analysis from position: 47
Branch analysis from position: 35
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 53
filename:       /in/VQAE4
function name:  dirToArray2
number of ops:  56
compiled vars:  !0 = $dir, !1 = $arr, !2 = $obj, !3 = $info, !4 = $path, !5 = $depth
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
   21     1        ASSIGN                                                   !1, <array>
   22     2        NEW                                              $7      'RecursiveIteratorIterator'
          3        NEW                                              $8      'RecursiveDirectoryIterator'
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0          
          6        SEND_VAR_NO_REF_EX                                       $8
          7        SEND_VAL_EX                                              2
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !2, $7
   23    10      > FE_RESET_R                                       $12     !2, ->53
         11    > > FE_FETCH_R                                               $12, !3, ->53
   24    12    >   INIT_METHOD_CALL                                         !3, 'getFilename'
         13        DO_FCALL                                      0  $13     
         14        IN_ARRAY                                                 $13, <array>
         15      > JMPZ                                                     ~14, ->17
         16    > > JMP                                                      ->11
   25    17    >   INIT_METHOD_CALL                                         !3, 'isDir'
         18        DO_FCALL                                      0  $15     
         19      > JMPZ                                                     $15, ->25
         20    >   INIT_METHOD_CALL                                         !3, 'getFilename'
         21        DO_FCALL                                      0  $16     
         22        INIT_ARRAY                                       ~17     <array>, $16
         23        QM_ASSIGN                                        ~18     ~17
         24      > JMP                                                      ->29
         25    >   INIT_METHOD_CALL                                         !3, 'getFilename'
         26        DO_FCALL                                      0  $19     
         27        INIT_ARRAY                                       ~20     $19
         28        QM_ASSIGN                                        ~18     ~20
         29    >   ASSIGN                                                   !4, ~18
   26    30        INIT_METHOD_CALL                                         !2, 'getDepth'
         31        DO_FCALL                                      0  $22     
         32        SUB                                              ~23     $22, 1
         33        ASSIGN                                                   !5, ~23
         34      > JMP                                                      ->45
   27    35    >   INIT_METHOD_CALL                                         !2, 'getSubIterator'
         36        SEND_VAR_EX                                              !5
         37        DO_FCALL                                      0  $25     
         38        INIT_METHOD_CALL                                         $25, 'current'
         39        DO_FCALL                                      0  $26     
         40        INIT_METHOD_CALL                                         $26, 'getFilename'
         41        DO_FCALL                                      0  $27     
         42        INIT_ARRAY                                       ~28     !4, $27
         43        ASSIGN                                                   !4, ~28
   26    44        PRE_DEC                                                  !5
         45    >   IS_SMALLER_OR_EQUAL                                      0, !5
         46      > JMPNZ                                                    ~31, ->35
   29    47    >   INIT_FCALL                                               'array_merge_recursive'
         48        SEND_VAR                                                 !1
         49        SEND_VAR                                                 !4
         50        DO_ICALL                                         $32     
         51        ASSIGN                                                   !1, $32
   23    52      > JMP                                                      ->11
         53    >   FE_FREE                                                  $12
   31    54      > RETURN                                                   !1
   32    55*     > RETURN                                                   null

End of function dirtoarray2

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.9 ms | 1408 KiB | 23 Q