List the files and directories within the images directory.
<?php $dir = “/images/”; // Sort in ascending order – this is default $a = scandir($dir); // Sort in descending order $b = scandir($dir,1); print_r($a); print_r($b); ?> |
Result:
Array ( [0] => . [1] => .. [2] => cat.gif [3] => dog.gif [4] => horse.gif [5] => myimages ) Array ( [0] => myimages [1] => horse.gif [2] => dog.gif [3] => cat.gif [4] => .. [5] => . ) |
The scandir()
function returns an array containing the files and directories within the specified directory.
scandir(directory, order, context) |
Parameter |
Description |
directory |
Required. Specifies the directory to scan. |
order |
Optional. Specifies the context for the directory handle, which consists of options that can modify the stream’s behavior. |
context |
Optional. Specifies the context for the directory handle, which consists of options that can modify the stream’s behavior. |
Return Value: |
Returns an array of files and directories on success, or |
PHP Version: |
5.0+ |
PHP Changelog: |
PHP 5.4: Added order constants. |