3v4l.org

run code in 300+ PHP versions simultaneously
<?PHP //directory to list, you choose; here we’ll just use the webroot $path = $_SERVER['DOCUMENT_ROOT']; //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 8.3.0 - 8.3.6
Warning: chdir(): open_basedir restriction in effect. File() is not within the allowed path(s): (/tmp:/in:/etc) in /in/O7c9t on line 7 Warning: scandir(): open_basedir restriction in effect. File(.) is not within the allowed path(s): (/tmp:/in:/etc) in /in/O7c9t on line 10 Warning: scandir(.): Failed to open directory: Operation not permitted in /in/O7c9t on line 10 Warning: scandir(): (errno 1): Operation not permitted in /in/O7c9t on line 10 Fatal error: Uncaught TypeError: array_diff(): Argument #1 ($array) must be of type array, false given in /in/O7c9t:10 Stack trace: #0 /in/O7c9t(10): array_diff(false, Array) #1 {main} thrown in /in/O7c9t on line 10
Process exited with code 255.
Output for 8.2.0 - 8.2.18
Warning: chdir(): open_basedir restriction in effect. File() is not within the allowed path(s): (/tmp:/in:/etc) in /in/O7c9t on line 7 Warning: scandir(): open_basedir restriction in effect. File(.) is not within the allowed path(s): (/tmp:/in:/etc) in /in/O7c9t on line 10 Warning: scandir(.): Failed to open directory: Operation not permitted in /in/O7c9t on line 10 Warning: scandir(): (errno 1): Operation not permitted in /in/O7c9t on line 10 Fatal error: Uncaught TypeError: array_diff(): Argument #1 ($array) must be of type array, bool given in /in/O7c9t:10 Stack trace: #0 /in/O7c9t(10): array_diff(false, Array) #1 {main} thrown in /in/O7c9t on line 10
Process exited with code 255.
Output for 8.0.14 - 8.0.30, 8.1.0 - 8.1.28
Warning: chdir(): open_basedir restriction in effect. File() is not within the allowed path(s): (/tmp:/in:/etc) in /in/O7c9t on line 7 Warning: scandir(): open_basedir restriction in effect. File(.) is not within the allowed path(s): (/tmp:/in:/etc) in /in/O7c9t on line 10 Warning: scandir(.): Failed to open directory: Operation not permitted in /in/O7c9t on line 10 Warning: scandir(): (errno 1): Operation not permitted in /in/O7c9t on line 10 Fatal error: Uncaught TypeError: array_diff(): Argument #1 ($array) must be of type array, bool given in /in/O7c9t:12 Stack trace: #0 /in/O7c9t(12): array_diff(false, Array) #1 {main} thrown in /in/O7c9t on line 12
Process exited with code 255.
Output for 8.0.0 - 8.0.13
Warning: chdir(): No such file or directory (errno 2) in /in/O7c9t on line 7 Fatal error: Uncaught Error: Call to undefined function create_function() in /in/O7c9t:17 Stack trace: #0 {main} thrown in /in/O7c9t on line 17
Process exited with code 255.
Output for 7.4.33
Warning: chdir(): No such file or directory (errno 2) in /in/O7c9t on line 7 Deprecated: Function create_function() is deprecated in /in/O7c9t on line 18 Warning: Cannot modify header information - headers already sent by (output started at /in/O7c9t:7) in /in/O7c9t on line 29 Array ( [0] => . [1] => .. [2] => bin [3] => boot [4] => dev [5] => etc [6] => home [7] => in [8] => lib [9] => lib64 [10] => mnt [11] => opt [12] => proc [13] => root [14] => run [15] => sbin [16] => srv [17] => sys [18] => tmp [19] => usr [20] => var )
Output for 7.4.26 - 7.4.32
Warning: chdir(): open_basedir restriction in effect. File() is not within the allowed path(s): (/tmp:/in:/etc) in /in/O7c9t on line 7 Warning: scandir(): open_basedir restriction in effect. File(.) is not within the allowed path(s): (/tmp:/in:/etc) in /in/O7c9t on line 10 Warning: scandir(.): failed to open dir: Operation not permitted in /in/O7c9t on line 10 Warning: scandir(): (errno 1): Operation not permitted in /in/O7c9t on line 10 Warning: array_diff(): Expected parameter 1 to be an array, bool given in /in/O7c9t on line 12 Deprecated: Function create_function() is deprecated in /in/O7c9t on line 18 Warning: usort() expects parameter 1 to be array, null given in /in/O7c9t on line 18 Warning: Cannot modify header information - headers already sent by (output started at /in/O7c9t:7) in /in/O7c9t on line 29
Output for 5.2.3 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.25
Warning: chdir(): No such file or directory (errno 2) in /in/O7c9t on line 7 Warning: Cannot modify header information - headers already sent by (output started at /in/O7c9t:7) in /in/O7c9t on line 29 Array ( [0] => . [1] => .. [2] => bin [3] => boot [4] => dev [5] => etc [6] => home [7] => in [8] => lib [9] => lib64 [10] => mnt [11] => opt [12] => proc [13] => root [14] => run [15] => sbin [16] => srv [17] => sys [18] => tmp [19] => usr [20] => var )
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.2
<br /> <b>Warning</b>: chdir() [<a href='function.chdir'>function.chdir</a>]: No such file or directory (errno 2) in <b>/in/O7c9t</b> on line <b>7</b><br /> <br /> <b>Warning</b>: scandir(.) [<a href='function.scandir'>function.scandir</a>]: failed to open dir: Permission denied in <b>/in/O7c9t</b> on line <b>10</b><br /> <br /> <b>Warning</b>: scandir() [<a href='function.scandir'>function.scandir</a>]: (errno 13): Permission denied in <b>/in/O7c9t</b> on line <b>10</b><br /> <br /> <b>Warning</b>: array_diff() [<a href='function.array-diff'>function.array-diff</a>]: Argument #1 is not an array in <b>/in/O7c9t</b> on line <b>13</b><br /> <br /> <b>Warning</b>: usort() [<a href='function.usort'>function.usort</a>]: The argument should be an array in <b>/in/O7c9t</b> on line <b>26</b><br />
Output for 4.4.5 - 4.4.9
<br /> <b>Warning</b>: chdir() [<a href='function.chdir'>function.chdir</a>]: No such file or directory (errno 2) in <b>/in/O7c9t</b> on line <b>7</b><br /> <br /> <b>Fatal error</b>: Call to undefined function: scandir() in <b>/in/O7c9t</b> on line <b>10</b><br />
Process exited with code 255.
Output for 4.4.3 - 4.4.4
<br /> <b>Warning</b>: chdir() [<a href='function.chdir'>function.chdir</a>]: No such file or directory (errno 2) in <b>/in/O7c9t</b> on line <b>7</b><br /> <br /> <b>Fatal error</b>: Call to undefined function: scandir() in <b>/in/O7c9t</b> on line <b>10</b><br />
Process exited with code 255.
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.2
<br /> <b>Warning</b>: chdir(): No such file or directory (errno 2) in <b>/in/O7c9t</b> on line <b>7</b><br /> <br /> <b>Fatal error</b>: Call to undefined function: scandir() in <b>/in/O7c9t</b> on line <b>10</b><br />
Process exited with code 255.
Output for 4.3.0 - 4.3.1
<br /> <b>Warning</b>: chdir() [<a href='http://www.php.net/function.chdir'>function.chdir</a>]: No such file or directory (errno 2) in <b>/in/O7c9t</b> on line <b>7</b><br /> <br /> <b>Fatal error</b>: Call to undefined function: scandir() in <b>/in/O7c9t</b> on line <b>10</b><br />

preferences:
268.58 ms | 402 KiB | 468 Q