3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?PHP //directory to list, you choose; here we’ll just use the webroot $path = $_SERVER['DOCUMENT_ROOT']+"/home/"; //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.1.0
Warning: A non-numeric value encountered in /in/XdGZA on line 3 Warning: A non-numeric value encountered in /in/XdGZA on line 3 Warning: chdir(): No such file or directory (errno 2) in /in/XdGZA on line 7 Warning: scandir(.): failed to open dir: Permission denied in /in/XdGZA on line 10 Warning: scandir(): (errno 13): Permission denied in /in/XdGZA on line 10 Warning: array_diff(): Argument #1 is not an array in /in/XdGZA on line 12 Warning: usort() expects parameter 1 to be array, null given in /in/XdGZA on line 26 Warning: Cannot modify header information - headers already sent by (output started at /in/XdGZA:3) in /in/XdGZA on line 29
Output for 7.0.0 - 7.0.14
Warning: chdir(): No such file or directory (errno 2) in /in/XdGZA on line 7 Warning: scandir(.): failed to open dir: Permission denied in /in/XdGZA on line 10 Warning: scandir(): (errno 13): Permission denied in /in/XdGZA on line 10 Warning: array_diff(): Argument #1 is not an array in /in/XdGZA on line 12 Warning: usort() expects parameter 1 to be array, null given in /in/XdGZA on line 26 Warning: Cannot modify header information - headers already sent by (output started at /in/XdGZA:7) in /in/XdGZA on line 29
Output for 5.3.0 - 5.6.28
Warning: chdir(): No such file or directory (errno 2) in /in/XdGZA on line 7 Warning: scandir(.): failed to open dir: Permission denied in /in/XdGZA on line 10 Warning: scandir(): (errno 13): Permission denied in /in/XdGZA on line 10 Warning: array_diff(): Argument #1 is not an array in /in/XdGZA on line 13 Warning: usort() expects parameter 1 to be array, null given in /in/XdGZA on line 26 Warning: Cannot modify header information - headers already sent by (output started at /in/XdGZA:7) in /in/XdGZA on line 29
Output for 5.2.3 - 5.2.17
Warning: chdir(): No such file or directory (errno 2) in /in/XdGZA on line 7 Warning: scandir(.): failed to open dir: Permission denied in /in/XdGZA on line 10 Warning: scandir(): (errno 13): Permission denied in /in/XdGZA on line 10 Warning: array_diff(): Argument #1 is not an array in /in/XdGZA on line 13 Warning: usort(): The argument should be an array in /in/XdGZA on line 26 Warning: Cannot modify header information - headers already sent by (output started at /in/XdGZA:7) in /in/XdGZA on line 29
Output for 5.0.0 - 5.2.2
Notice: Undefined index: DOCUMENT_ROOT in /in/XdGZA on line 3 Warning: chdir(): No such file or directory (errno 2) in /in/XdGZA on line 7 Warning: scandir(.): failed to open dir: Permission denied in /in/XdGZA on line 10 Warning: scandir(): (errno 13): Permission denied in /in/XdGZA on line 10 Warning: array_diff(): Argument #1 is not an array in /in/XdGZA on line 13 Warning: usort(): The argument should be an array in /in/XdGZA on line 26
Output for 4.4.5 - 4.4.9
Notice: Undefined index: DOCUMENT_ROOT in /in/XdGZA on line 3 Warning: chdir(): No such file or directory (errno 2) in /in/XdGZA on line 7 Fatal error: Call to undefined function: scandir() in /in/XdGZA on line 10
Process exited with code 255.
Output for 4.3.2 - 4.4.4
Notice: Undefined index: DOCUMENT_ROOT in /in/XdGZA on line 3 Warning: chdir(): No such file or directory (errno 2) in /in/XdGZA on line 7 Fatal error: Call to undefined function: scandir() in /in/XdGZA on line 10
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Notice: Undefined index: DOCUMENT_ROOT in /in/XdGZA on line 3 Warning: chdir() [http://www.php.net/function.chdir]: No such file or directory (errno 2) in /in/XdGZA on line 7 Fatal error: Call to undefined function: scandir() in /in/XdGZA on line 10