@ 2023-01-14T10:45:05Z <?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;
}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 8.4.2 0.011 0.011 26.00 8.4.1 0.017 0.003 23.81 8.3.15 0.004 0.016 17.20 8.3.14 0.016 0.003 16.59 8.3.13 0.006 0.003 18.53 8.3.12 0.013 0.006 18.88 8.3.11 0.011 0.008 18.18 8.3.10 0.000 0.008 24.06 8.3.9 0.006 0.006 26.77 8.3.8 0.009 0.000 18.30 8.3.7 0.012 0.003 16.38 8.3.6 0.010 0.007 16.50 8.3.5 0.009 0.006 16.35 8.3.4 0.017 0.003 20.30 8.3.3 0.013 0.003 18.84 8.3.2 0.004 0.004 24.18 8.3.1 0.003 0.005 24.66 8.3.0 0.005 0.003 26.16 8.2.27 0.004 0.004 17.13 8.2.26 0.009 0.009 16.45 8.2.25 0.015 0.006 16.66 8.2.24 0.006 0.003 17.42 8.2.23 0.007 0.003 20.94 8.2.22 0.004 0.004 37.54 8.2.21 0.011 0.007 26.77 8.2.20 0.006 0.003 16.63 8.2.19 0.016 0.003 16.63 8.2.18 0.007 0.011 16.50 8.2.17 0.008 0.008 22.96 8.2.16 0.007 0.007 22.96 8.2.15 0.004 0.004 25.66 8.2.14 0.000 0.008 24.66 8.2.13 0.009 0.000 26.16 8.2.12 0.004 0.004 19.89 8.2.11 0.003 0.007 19.32 8.2.10 0.013 0.003 17.91 8.2.9 0.003 0.005 17.75 8.2.8 0.003 0.006 19.10 8.2.7 0.008 0.000 17.63 8.2.6 0.003 0.006 17.63 8.2.5 0.000 0.009 17.55 8.2.4 0.008 0.000 20.06 8.2.3 0.005 0.003 18.25 8.2.2 0.005 0.002 19.34 8.2.1 0.018 0.000 17.73 8.2.0 0.011 0.008 17.85 8.1.31 0.014 0.004 18.63 8.1.30 0.009 0.000 20.11 8.1.29 0.003 0.006 18.88 8.1.28 0.010 0.010 25.92 8.1.27 0.000 0.008 24.66 8.1.26 0.008 0.000 26.35 8.1.25 0.004 0.004 28.09 8.1.24 0.009 0.000 19.33 8.1.23 0.004 0.007 20.85 8.1.22 0.004 0.004 17.75 8.1.21 0.004 0.004 18.77 8.1.20 0.003 0.006 17.38 8.1.19 0.000 0.008 17.23 8.1.18 0.000 0.008 18.10 8.1.17 0.000 0.008 18.59 8.1.16 0.006 0.003 19.03 8.1.15 0.000 0.007 18.56 8.1.14 0.015 0.003 17.30 8.1.13 0.000 0.018 17.43 8.1.12 0.018 0.000 17.43 8.1.11 0.011 0.008 17.55 8.1.10 0.016 0.002 17.51 8.1.9 0.013 0.007 17.52 8.1.8 0.013 0.004 17.46 8.1.7 0.011 0.005 17.43 8.1.6 0.014 0.006 17.70 8.1.5 0.011 0.004 17.69 8.1.4 0.007 0.011 17.74 8.1.3 0.012 0.008 17.71 8.1.2 0.016 0.000 17.71 8.1.1 0.003 0.013 17.52 8.1.0 0.005 0.010 17.50 8.0.30 0.000 0.008 21.52 8.0.29 0.003 0.006 16.75 8.0.28 0.004 0.004 18.54 8.0.27 0.005 0.010 16.84 8.0.26 0.005 0.010 16.88 8.0.25 0.014 0.003 16.86 8.0.24 0.012 0.002 16.82 8.0.23 0.013 0.003 16.97 8.0.22 0.012 0.004 16.91 8.0.21 0.017 0.000 16.81 8.0.20 0.014 0.000 16.93 8.0.19 0.011 0.003 16.97 8.0.18 0.013 0.004 16.86 8.0.17 0.003 0.010 16.98 8.0.16 0.011 0.004 16.83 8.0.15 0.011 0.006 16.93 8.0.14 0.012 0.006 16.86 8.0.13 0.011 0.004 16.87 8.0.12 0.006 0.009 16.78 8.0.11 0.010 0.003 16.82 8.0.10 0.007 0.007 16.74 8.0.9 0.011 0.005 16.86 8.0.8 0.008 0.003 16.91 8.0.7 0.012 0.008 16.80 8.0.6 0.016 0.008 16.76 8.0.5 0.017 0.000 16.93 8.0.3 0.012 0.008 16.87 8.0.2 0.009 0.009 16.84 8.0.1 0.009 0.009 16.81
preferences:dark mode live preview
74.84 ms | 403 KiB | 5 Q