3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php //directory to list, you choose; here we’ll just use the webroot $path = '.'; //warning: `is_dir` will need you to change to the parent directory of what you are testing //see <uk3.php.net/manual/en/function.is-dir.php#70005> for details chdir ($path); //get a directory listing $dir = array_diff (scandir ('.'), //folders / files to ignore array ('.DS_Store', 'Thumbs.db') ); //sort folders first, then by type, then alphabetically usort ($dir, create_function ('$a,$b', 'return is_dir ($a) ? (is_dir ($b) ? strnatcasecmp ($a, $b) : -1) : (is_dir ($b) ? 1 : ( strcasecmp (pathinfo ($a, PATHINFO_EXTENSION), pathinfo ($b, PATHINFO_EXTENSION)) == 0 ? strnatcasecmp ($a, $b) : strcasecmp (pathinfo ($a, PATHINFO_EXTENSION), pathinfo ($b, PATHINFO_EXTENSION)) )) ; ')); //echo to screen header ('content-type: text/plain'); print_r ($dir);
Output for 7.3.0rc3 - 7.3.0rc4
Warning: chdir(): open_basedir restriction in effect. File(.) is not within the allowed path(s): (/tmp:/in:/etc) in /in/Cm8Fu on line 7 Warning: scandir(): open_basedir restriction in effect. File(.) is not within the allowed path(s): (/tmp:/in:/etc) in /in/Cm8Fu on line 10 Warning: scandir(.): failed to open dir: Operation not permitted in /in/Cm8Fu on line 10 Warning: scandir(): (errno 1): Operation not permitted in /in/Cm8Fu on line 10 Warning: array_diff(): Expected parameter 1 to be an array, bool given in /in/Cm8Fu on line 12 Deprecated: Function create_function() is deprecated in /in/Cm8Fu on line 18 Warning: usort() expects parameter 1 to be array, null given in /in/Cm8Fu on line 18 Warning: Cannot modify header information - headers already sent by (output started at /in/Cm8Fu:7) in /in/Cm8Fu on line 29
Output for 7.2.0, 7.3.0alpha1 - 7.3.0beta1
Warning: scandir(.): failed to open dir: Permission denied in /in/Cm8Fu on line 10 Warning: scandir(): (errno 13): Permission denied in /in/Cm8Fu on line 10 Warning: array_diff(): Argument #1 is not an array in /in/Cm8Fu on line 12 Deprecated: Function create_function() is deprecated in /in/Cm8Fu on line 18 Warning: usort() expects parameter 1 to be array, null given in /in/Cm8Fu on line 18 Warning: Cannot modify header information - headers already sent by (output started at /in/Cm8Fu:10) in /in/Cm8Fu on line 29
Output for 7.2.6
Warning: chdir(): open_basedir restriction in effect. File(.) is not within the allowed path(s): (/tmp:/in) in /in/Cm8Fu on line 7 Warning: scandir(): open_basedir restriction in effect. File(.) is not within the allowed path(s): (/tmp:/in) in /in/Cm8Fu on line 10 Warning: scandir(.): failed to open dir: Operation not permitted in /in/Cm8Fu on line 10 Warning: scandir(): (errno 1): Operation not permitted in /in/Cm8Fu on line 10 Warning: array_diff(): Argument #1 is not an array in /in/Cm8Fu on line 12 Deprecated: Function create_function() is deprecated in /in/Cm8Fu on line 18 Warning: usort() expects parameter 1 to be array, null given in /in/Cm8Fu on line 18 Warning: Cannot modify header information - headers already sent by (output started at /in/Cm8Fu:7) in /in/Cm8Fu on line 29
Output for 7.1.20
Warning: chdir(): open_basedir restriction in effect. File(.) is not within the allowed path(s): (/tmp:/in) in /in/Cm8Fu on line 7 Warning: scandir(): open_basedir restriction in effect. File(.) is not within the allowed path(s): (/tmp:/in) in /in/Cm8Fu on line 10 Warning: scandir(.): failed to open dir: Operation not permitted in /in/Cm8Fu on line 10 Warning: scandir(): (errno 1): Operation not permitted in /in/Cm8Fu on line 10 Warning: array_diff(): Argument #1 is not an array in /in/Cm8Fu on line 12 Warning: usort() expects parameter 1 to be array, null given in /in/Cm8Fu on line 18 Warning: Cannot modify header information - headers already sent by (output started at /in/Cm8Fu:7) in /in/Cm8Fu on line 29
Output for 7.0.20, 7.1.5 - 7.1.10
Warning: scandir(.): failed to open dir: Permission denied in /in/Cm8Fu on line 10 Warning: scandir(): (errno 13): Permission denied in /in/Cm8Fu on line 10 Warning: array_diff(): Argument #1 is not an array in /in/Cm8Fu on line 12 Warning: usort() expects parameter 1 to be array, null given in /in/Cm8Fu on line 18 Warning: Cannot modify header information - headers already sent by (output started at /in/Cm8Fu:10) in /in/Cm8Fu on line 29
Output for 7.0.0 - 7.0.14, 7.1.0
Warning: scandir(.): failed to open dir: Permission denied in /in/Cm8Fu on line 10 Warning: scandir(): (errno 13): Permission denied in /in/Cm8Fu on line 10 Warning: array_diff(): Argument #1 is not an array in /in/Cm8Fu on line 12 Warning: usort() expects parameter 1 to be array, null given in /in/Cm8Fu on line 26 Warning: Cannot modify header information - headers already sent by (output started at /in/Cm8Fu:10) in /in/Cm8Fu on line 29
Output for 5.3.0 - 5.6.28
Warning: scandir(.): failed to open dir: Permission denied in /in/Cm8Fu on line 10 Warning: scandir(): (errno 13): Permission denied in /in/Cm8Fu on line 10 Warning: array_diff(): Argument #1 is not an array in /in/Cm8Fu on line 13 Warning: usort() expects parameter 1 to be array, null given in /in/Cm8Fu on line 26 Warning: Cannot modify header information - headers already sent by (output started at /in/Cm8Fu:10) in /in/Cm8Fu on line 29
Output for 5.2.3 - 5.2.17
Warning: scandir(.): failed to open dir: Permission denied in /in/Cm8Fu on line 10 Warning: scandir(): (errno 13): Permission denied in /in/Cm8Fu on line 10 Warning: array_diff(): Argument #1 is not an array in /in/Cm8Fu on line 13 Warning: usort(): The argument should be an array in /in/Cm8Fu on line 26 Warning: Cannot modify header information - headers already sent by (output started at /in/Cm8Fu:10) in /in/Cm8Fu on line 29
Output for 5.0.0 - 5.2.2
Warning: scandir(.): failed to open dir: Permission denied in /in/Cm8Fu on line 10 Warning: scandir(): (errno 13): Permission denied in /in/Cm8Fu on line 10 Warning: array_diff(): Argument #1 is not an array in /in/Cm8Fu on line 13 Warning: usort(): The argument should be an array in /in/Cm8Fu on line 26
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: scandir() in /in/Cm8Fu on line 10
Process exited with code 255.
Output for 4.3.2 - 4.4.4
Fatal error: Call to undefined function: scandir() in /in/Cm8Fu on line 10
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: scandir() in /in/Cm8Fu on line 10