3v4l.org

run code in 300+ PHP versions simultaneously
<?php if ( ! function_exists( 'str_ends_with' ) ) { function str_ends_with( $haystack, $needle ) { // Yes, I know, but I'm coding on mobile. forgive_me() return 0 === strpos( strrev( $haystack ), strrev( $needle ) ); } } $dirlist = array ( 'folder' => array ( 'name' => 'folder', 'perms' => 'urwxr-xr-x', 'permsn' => '0755', 'number' => false, 'owner' => false, 'group' => false, 'size' => 4096, 'lastmodunix' => 1673689008, 'lastmod' => 'Jan 14', 'time' => '09:36:48', 'type' => 'd', 'files' => array ( 'subfile.php' => array ( 'name' => 'subfile.php', 'perms' => 'urw-r--r--', 'permsn' => '0644', 'number' => false, 'owner' => false, 'group' => false, 'size' => 0, 'lastmodunix' => 1673689008, 'lastmod' => 'Jan 14', 'time' => '09:36:48', 'type' => 'f', ), 'subfolder' => array ( 'name' => 'subfolder', 'perms' => 'urwxr-xr-x', 'permsn' => '0755', 'number' => false, 'owner' => false, 'group' => false, 'size' => 4096, 'lastmodunix' => 1673689982, 'lastmod' => 'Jan 14', 'time' => '09:53:02', 'type' => 'd', 'files' => array ( 'subsubfile.php' => array ( 'name' => 'subsubfile.php', 'perms' => 'urw-r--r--', 'permsn' => '0644', 'number' => false, 'owner' => false, 'group' => false, 'size' => 0, 'lastmodunix' => 1673689982, 'lastmod' => 'Jan 14', 'time' => '09:53:02', 'type' => 'f', ), ), ), ), ), 'file.php' => array ( 'name' => 'file.php', 'perms' => 'urw-r--r--', 'permsn' => '0644', 'number' => false, 'owner' => false, 'group' => false, 'size' => 0, 'lastmodunix' => 1673689019, 'lastmod' => 'Jan 14', 'time' => '09:36:59', 'type' => 'f', ), ); $path = trailingslashit( '/root' ); echo headerme( 'Expected' ); echo $path, 'folder/subfile.php', PHP_EOL; echo $path, 'folder/subfolder/subsubfile.php', PHP_EOL; echo $path, 'file.php', PHP_EOL; echo headerme( 'array_walk_recursive()' ); array_walk_recursive( $dirlist, function ( $value, $key, $path ) { if ( str_ends_with( $value, '.php' ) ) { echo $path, $value, PHP_EOL; } }, $path ); echo headerme( 'map_deep()' ); map_deep( $dirlist, function( $value ) use ( $path ) { if ( str_ends_with( $value, '.php' ) ) { echo $path, $value, PHP_EOL; } } ); echo headerme( 'map_deep_with_index()' ); map_deep_with_index( $dirlist, function( $value, $key ) use ( $path ) { if ( str_ends_with( $value, '.php' ) ) { echo $path, $value, PHP_EOL; } } ); function map_deep( $value, $callback ) { if ( is_array( $value ) ) { foreach ( $value as $index => $item ) { $value[ $index ] = map_deep( $item, $callback ); } } elseif ( is_object( $value ) ) { $object_vars = get_object_vars( $value ); foreach ( $object_vars as $property_name => $property_value ) { $value->$property_name = map_deep( $property_value, $callback ); } } else { $value = call_user_func( $callback, $value ); } return $value; } function map_deep_with_index( $value, $callback, $index = null ) { if ( is_array( $value ) ) { foreach ( $value as $index => $item ) { $value[ $index ] = map_deep_with_index( $item, $callback, $index ); } } elseif ( is_object( $value ) ) { $object_vars = get_object_vars( $value ); foreach ( $object_vars as $property_name => $property_value ) { $value->$property_name = map_deep_with_index( $property_value, $callback ); } } else { $value = call_user_func( $callback, $value, $index ); } return $value; } function trailingslashit( $str ) { return rtrim( $str, '/' ) . '/'; } function headerme( $str ) { $equals = str_pad( '', mb_strlen( $str ), '=' ); return PHP_EOL . PHP_EOL . $equals . PHP_EOL . $str . PHP_EOL . $equals . PHP_EOL . PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
filename:       /in/QbdOh
function name:  (null)
number of ops:  55
compiled vars:  !0 = $dirlist, !1 = $path
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   INIT_FCALL                                               'function_exists'
          1        SEND_VAL                                                 'str_ends_with'
          2        DO_ICALL                                         $2      
          3        BOOL_NOT                                         ~3      $2
          4      > JMPZ                                                     ~3, ->6
    3     5    >   DECLARE_FUNCTION                                         'str_ends_with'
    9     6    >   ASSIGN                                                   !0, <array>
   88     7        INIT_FCALL_BY_NAME                                       'trailingslashit'
          8        SEND_VAL_EX                                              '%2Froot'
          9        DO_FCALL                                      0  $5      
         10        ASSIGN                                                   !1, $5
   90    11        INIT_FCALL_BY_NAME                                       'headerme'
         12        SEND_VAL_EX                                              'Expected'
         13        DO_FCALL                                      0  $7      
         14        ECHO                                                     $7
   91    15        ECHO                                                     !1
         16        ECHO                                                     'folder%2Fsubfile.php'
         17        ECHO                                                     '%0A'
   92    18        ECHO                                                     !1
         19        ECHO                                                     'folder%2Fsubfolder%2Fsubsubfile.php'
         20        ECHO                                                     '%0A'
   93    21        ECHO                                                     !1
         22        ECHO                                                     'file.php'
         23        ECHO                                                     '%0A'
   95    24        INIT_FCALL_BY_NAME                                       'headerme'
         25        SEND_VAL_EX                                              'array_walk_recursive%28%29'
         26        DO_FCALL                                      0  $8      
         27        ECHO                                                     $8
   96    28        INIT_FCALL                                               'array_walk_recursive'
   97    29        SEND_REF                                                 !0
   98    30        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FQbdOh%3A98%241'
  102    31        SEND_VAL                                                 ~9
  103    32        SEND_VAR                                                 !1
         33        DO_ICALL                                                 
  106    34        INIT_FCALL_BY_NAME                                       'headerme'
         35        SEND_VAL_EX                                              'map_deep%28%29'
         36        DO_FCALL                                      0  $11     
         37        ECHO                                                     $11
  107    38        INIT_FCALL_BY_NAME                                       'map_deep'
  108    39        SEND_VAR_EX                                              !0
  109    40        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FQbdOh%3A109%242'
         41        BIND_LEXICAL                                             ~12, !1
  113    42        SEND_VAL_EX                                              ~12
         43        DO_FCALL                                      0          
  116    44        INIT_FCALL_BY_NAME                                       'headerme'
         45        SEND_VAL_EX                                              'map_deep_with_index%28%29'
         46        DO_FCALL                                      0  $14     
         47        ECHO                                                     $14
  117    48        INIT_FCALL_BY_NAME                                       'map_deep_with_index'
  118    49        SEND_VAR_EX                                              !0
  119    50        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FQbdOh%3A119%243'
         51        BIND_LEXICAL                                             ~15, !1
  123    52        SEND_VAL_EX                                              ~15
         53        DO_FCALL                                      0          
  167    54      > RETURN                                                   1

Function %00str_ends_with%2Fin%2FQbdOh%3A3%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QbdOh
function name:  str_ends_with
number of ops:  15
compiled vars:  !0 = $haystack, !1 = $needle
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        INIT_FCALL                                               'strpos'
          3        INIT_FCALL                                               'strrev'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $2      
          6        SEND_VAR                                                 $2
          7        INIT_FCALL                                               'strrev'
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                         $3      
         10        SEND_VAR                                                 $3
         11        DO_ICALL                                         $4      
         12        IS_IDENTICAL                                     ~5      $4, 0
         13      > RETURN                                                   ~5
    6    14*     > RETURN                                                   null

End of function %00str_ends_with%2Fin%2FQbdOh%3A3%240

Function %00%7Bclosure%7D%2Fin%2FQbdOh%3A98%241:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 11
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/QbdOh
function name:  {closure}
number of ops:  12
compiled vars:  !0 = $value, !1 = $key, !2 = $path
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   98     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   99     3        INIT_FCALL                                               'str_ends_with'
          4        SEND_VAR                                                 !0
          5        SEND_VAL                                                 '.php'
          6        DO_ICALL                                         $3      
          7      > JMPZ                                                     $3, ->11
  100     8    >   ECHO                                                     !2
          9        ECHO                                                     !0
         10        ECHO                                                     '%0A'
  102    11    > > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FQbdOh%3A98%241

Function %00%7Bclosure%7D%2Fin%2FQbdOh%3A109%242:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 10
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/QbdOh
function name:  {closure}
number of ops:  11
compiled vars:  !0 = $value, !1 = $path
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  109     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
  110     2        INIT_FCALL                                               'str_ends_with'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 '.php'
          5        DO_ICALL                                         $2      
          6      > JMPZ                                                     $2, ->10
  111     7    >   ECHO                                                     !1
          8        ECHO                                                     !0
          9        ECHO                                                     '%0A'
  113    10    > > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FQbdOh%3A109%242

Function %00%7Bclosure%7D%2Fin%2FQbdOh%3A119%243:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 11
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/QbdOh
function name:  {closure}
number of ops:  12
compiled vars:  !0 = $value, !1 = $key, !2 = $path
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  119     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
  120     3        INIT_FCALL                                               'str_ends_with'
          4        SEND_VAR                                                 !0
          5        SEND_VAL                                                 '.php'
          6        DO_ICALL                                         $3      
          7      > JMPZ                                                     $3, ->11
  121     8    >   ECHO                                                     !2
          9        ECHO                                                     !0
         10        ECHO                                                     '%0A'
  123    11    > > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FQbdOh%3A119%243

Function map_deep:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 16
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 14
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 14
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 34
Branch analysis from position: 18
2 jumps found. (Code = 77) Position 1 = 23, Position 2 = 32
Branch analysis from position: 23
2 jumps found. (Code = 78) Position 1 = 24, Position 2 = 32
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
Branch analysis from position: 32
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QbdOh
function name:  map_deep
number of ops:  40
compiled vars:  !0 = $value, !1 = $callback, !2 = $item, !3 = $index, !4 = $object_vars, !5 = $property_value, !6 = $property_name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  126     0  E >   RECV                                             !0      
          1        RECV                                             !1      
  127     2        TYPE_CHECK                                  128          !0
          3      > JMPZ                                                     ~7, ->16
  128     4    > > FE_RESET_R                                       $8      !0, ->14
          5    > > FE_FETCH_R                                       ~9      $8, !2, ->14
          6    >   ASSIGN                                                   !3, ~9
  129     7        INIT_FCALL_BY_NAME                                       'map_deep'
          8        SEND_VAR_EX                                              !2
          9        SEND_VAR_EX                                              !1
         10        DO_FCALL                                      0  $12     
         11        ASSIGN_DIM                                               !0, !3
         12        OP_DATA                                                  $12
  128    13      > JMP                                                      ->5
         14    >   FE_FREE                                                  $8
         15      > JMP                                                      ->38
  131    16    >   TYPE_CHECK                                  256          !0
         17      > JMPZ                                                     ~13, ->34
  132    18    >   INIT_FCALL                                               'get_object_vars'
         19        SEND_VAR                                                 !0
         20        DO_ICALL                                         $14     
         21        ASSIGN                                                   !4, $14
  133    22      > FE_RESET_R                                       $16     !4, ->32
         23    > > FE_FETCH_R                                       ~17     $16, !5, ->32
         24    >   ASSIGN                                                   !6, ~17
  134    25        INIT_FCALL_BY_NAME                                       'map_deep'
         26        SEND_VAR_EX                                              !5
         27        SEND_VAR_EX                                              !1
         28        DO_FCALL                                      0  $20     
         29        ASSIGN_OBJ                                               !0, !6
         30        OP_DATA                                                  $20
  133    31      > JMP                                                      ->23
         32    >   FE_FREE                                                  $16
         33      > JMP                                                      ->38
  137    34    >   INIT_USER_CALL                                1          'call_user_func', !1
         35        SEND_USER                                                !0
         36        DO_FCALL                                      0  $21     
         37        ASSIGN                                                   !0, $21
  140    38    > > RETURN                                                   !0
  141    39*     > RETURN                                                   null

End of function map_deep

Function map_deep_with_index:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 18
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 16
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 16
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 36
Branch analysis from position: 20
2 jumps found. (Code = 77) Position 1 = 25, Position 2 = 34
Branch analysis from position: 25
2 jumps found. (Code = 78) Position 1 = 26, Position 2 = 34
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
Branch analysis from position: 34
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QbdOh
function name:  map_deep_with_index
number of ops:  43
compiled vars:  !0 = $value, !1 = $callback, !2 = $index, !3 = $item, !4 = $object_vars, !5 = $property_value, !6 = $property_name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  143     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      null
  144     3        TYPE_CHECK                                  128          !0
          4      > JMPZ                                                     ~7, ->18
  145     5    > > FE_RESET_R                                       $8      !0, ->16
          6    > > FE_FETCH_R                                       ~9      $8, !3, ->16
          7    >   ASSIGN                                                   !2, ~9
  146     8        INIT_FCALL_BY_NAME                                       'map_deep_with_index'
          9        SEND_VAR_EX                                              !3
         10        SEND_VAR_EX                                              !1
         11        SEND_VAR_EX                                              !2
         12        DO_FCALL                                      0  $12     
         13        ASSIGN_DIM                                               !0, !2
         14        OP_DATA                                                  $12
  145    15      > JMP                                                      ->6
         16    >   FE_FREE                                                  $8
         17      > JMP                                                      ->41
  148    18    >   TYPE_CHECK                                  256          !0
         19      > JMPZ                                                     ~13, ->36
  149    20    >   INIT_FCALL                                               'get_object_vars'
         21        SEND_VAR                                                 !0
         22        DO_ICALL                                         $14     
         23        ASSIGN                                                   !4, $14
  150    24      > FE_RESET_R                                       $16     !4, ->34
         25    > > FE_FETCH_R                                       ~17     $16, !5, ->34
         26    >   ASSIGN                                                   !6, ~17
  151    27        INIT_FCALL_BY_NAME                                       'map_deep_with_index'
         28        SEND_VAR_EX                                              !5
         29        SEND_VAR_EX                                              !1
         30        DO_FCALL                                      0  $20     
         31        ASSIGN_OBJ                                               !0, !6
         32        OP_DATA                                                  $20
  150    33      > JMP                                                      ->25
         34    >   FE_FREE                                                  $16
         35      > JMP                                                      ->41
  154    36    >   INIT_USER_CALL                                2          'call_user_func', !1
         37        SEND_USER                                                !0
         38        SEND_USER                                                !2
         39        DO_FCALL                                      0  $21     
         40        ASSIGN                                                   !0, $21
  157    41    > > RETURN                                                   !0
  158    42*     > RETURN                                                   null

End of function map_deep_with_index

Function trailingslashit:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QbdOh
function name:  trailingslashit
number of ops:  8
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  160     0  E >   RECV                                             !0      
  161     1        INIT_FCALL                                               'rtrim'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 '%2F'
          4        DO_ICALL                                         $1      
          5        CONCAT                                           ~2      $1, '%2F'
          6      > RETURN                                                   ~2
  162     7*     > RETURN                                                   null

End of function trailingslashit

Function headerme:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QbdOh
function name:  headerme
number of ops:  19
compiled vars:  !0 = $str, !1 = $equals
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  164     0  E >   RECV                                             !0      
  165     1        INIT_FCALL                                               'str_pad'
          2        SEND_VAL                                                 ''
          3        INIT_FCALL                                               'mb_strlen'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $2      
          6        SEND_VAR                                                 $2
          7        SEND_VAL                                                 '%3D'
          8        DO_ICALL                                         $3      
          9        ASSIGN                                                   !1, $3
  166    10        CONCAT                                           ~5      '%0A%0A', !1
         11        CONCAT                                           ~6      ~5, '%0A'
         12        CONCAT                                           ~7      ~6, !0
         13        CONCAT                                           ~8      ~7, '%0A'
         14        CONCAT                                           ~9      ~8, !1
         15        CONCAT                                           ~10     ~9, '%0A'
         16        CONCAT                                           ~11     ~10, '%0A'
         17      > RETURN                                                   ~11
  167    18*     > RETURN                                                   null

End of function headerme

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.38 ms | 1420 KiB | 31 Q