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 = './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 5.5.24 - 5.5.32, 5.5.34 - 5.6.17, 5.6.20 - 5.6.28, hhvm-3.10.0, 7.0.0 - 7.0.3, 7.0.5 - 7.1.0
Array ( [0] => . [1] => .. )
Output for 7.0.4
Warning: scandir(.): failed to open dir: Permission denied in /in/ks8R2 on line 10 Warning: scandir(): (errno 13): Permission denied in /in/ks8R2 on line 10 Warning: array_diff(): Argument #1 is not an array in /in/ks8R2 on line 12 Warning: usort() expects parameter 1 to be array, null given in /in/ks8R2 on line 26 Warning: Cannot modify header information - headers already sent by (output started at /in/ks8R2:10) in /in/ks8R2 on line 29
Output for hhvm-3.12.0
Warning: Permission denied in /in/ks8R2 on line 10 Warning: array_diff() expects parameter 1 to be an array or collection in /in/ks8R2 on line 13 Warning: Invalid operand type was used: usort expects array(s) or collection(s) in /in/ks8R2 on line 26
Output for 5.3.0 - 5.4.45, 5.5.33, 5.6.18 - 5.6.19
Warning: scandir(.): failed to open dir: Permission denied in /in/ks8R2 on line 10 Warning: scandir(): (errno 13): Permission denied in /in/ks8R2 on line 10 Warning: array_diff(): Argument #1 is not an array in /in/ks8R2 on line 13 Warning: usort() expects parameter 1 to be array, null given in /in/ks8R2 on line 26 Warning: Cannot modify header information - headers already sent by (output started at /in/ks8R2:10) in /in/ks8R2 on line 29
Output for 5.2.3 - 5.2.17
Warning: scandir(.): failed to open dir: Permission denied in /in/ks8R2 on line 10 Warning: scandir(): (errno 13): Permission denied in /in/ks8R2 on line 10 Warning: array_diff(): Argument #1 is not an array in /in/ks8R2 on line 13 Warning: usort(): The argument should be an array in /in/ks8R2 on line 26 Warning: Cannot modify header information - headers already sent by (output started at /in/ks8R2:10) in /in/ks8R2 on line 29
Output for 5.0.0 - 5.2.2
Warning: chdir(): No such file or directory (errno 2) in /in/ks8R2 on line 7 Warning: scandir(.): failed to open dir: Permission denied in /in/ks8R2 on line 10 Warning: scandir(): (errno 13): Permission denied in /in/ks8R2 on line 10 Warning: array_diff(): Argument #1 is not an array in /in/ks8R2 on line 13 Warning: usort(): The argument should be an array in /in/ks8R2 on line 26
Output for 4.4.5 - 4.4.9
Warning: chdir(): No such file or directory (errno 2) in /in/ks8R2 on line 7 Fatal error: Call to undefined function: scandir() in /in/ks8R2 on line 10
Process exited with code 255.
Output for 4.3.2 - 4.4.4
Warning: chdir(): No such file or directory (errno 2) in /in/ks8R2 on line 7 Fatal error: Call to undefined function: scandir() in /in/ks8R2 on line 10
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Warning: chdir() [http://www.php.net/function.chdir]: No such file or directory (errno 2) in /in/ks8R2 on line 7 Fatal error: Call to undefined function: scandir() in /in/ks8R2 on line 10