PHP scandir() function: Here, we will find out about the PHP scandir() function with its syntax, parameters, returns a type, and example.
PHP scandir() function
The full type of scandir is “Output Directory“, the function scandir() is utilized to get the rundown of the records and indexes accessible in the predefined catalogue.
scandir(directory, sorting_order, setting);
- catalogue – It indicates the index name (or way) from that point we need to get the rundown of the documents and registries
- arranging – It is a discretionary parameter; its default value is o (one after another in order arranging request). 1 can be accustomed to plummeting request.
- setting – It is a discretionary parameter; it is utilized to determine the unique situation (a lot of alternatives that can change the conduct of the stream) to the index handle.
It restores a variety of the documents and catalogues, returns “False” on function execution disappointment.
Example: PHP code to get and print the rundown of documents and catalogues of a given index
<?php //directory name $path = "/home"; //assigning the return array in $arr1 //defualt in ascending order $arr1 = scandir($path); //assigning the return array in $arr2 //Using 1 for descending order $arr2 = scandir($path,1); //printing the results print_r($arr1); print_r($arr2); ?>
Array (  => .  => ..  => folder1  => folder2  => folder3  => main.php ) Array (  => main.php  => folder3  => folder2  => folder1  => ..  => . )