PHP scandir() Function

PHP scandir Function


Definition :

In php  scandir() Function is inbuilt function.The scandir() function is used to returns an array of files and directories of the specified directory. The scandir() function lists the files and directories which are present inside a specified path. The directory, stream behavior, and sorting_order of the files and directories are passed as a parameter to the scandir() function and it returns an array of filenames on success, or false on failure. 

Syntax

  scandir(directoryordercontext)

Parameter 
Parameter Description
directory Required. Specifies the directory to be scanned
order Optional. Specifies the sorting order. Default sort order is alphabetical in ascending order (0). Set to SCANDIR_SORT_DESCENDING or 1 to sort in alphabetical descending order, or SCANDIR_SORT_NONE to return the result unsorted 
context Optional. Specifies the context of the directory handle. Context is a set of options that can modify the behavior of a stream

Given below example of use of  scandir() Function

Output :

(
[0] => .
[1] => ..
[2] => aboutus.php
[3] => contact.php
[4] => index.php 
[5] => terms.php
)