How does PHP read directories into an array
This article mainly introduces the PHP how to read the directory into the array of related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this PHP how to read the directory into the array article will have a harvest, let's take a look.
The scandir () function in PHP reads directories into an array. The scandir () function reads the contents of the specified directory (files and folders) and, if successful, returns an array of file and folder names with the syntax "scandir (the directory to be read, the order, the environment of the directory handle);"
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
The scandir () function in PHP reads directories into an array.
Two functions, readdir () and scandir (), are provided in PHP to read the contents of a specified directory, where the scandir () function can store the read directory contents (file and folder names) into an array.
Scandir (directory,sorting_order,context); parameter description directory is required. Specifies the directory to scan. Sorting_order is optional. Specify the order of arrangement. The default is 0, which means it is sorted in ascending alphabetical order. If set to SCANDIR_SORT_DESCENDING or 1, it is sorted in descending alphabetical order. If set to SCANDIR_SORT_NONE, unarranged results are returned. Context is optional. Specifies the environment of the directory handle. Context is a set of options that can modify the behavior of a directory stream.
The successful execution of the scandir () function returns an array of file and folder names, or FALSE if execution fails. If the parameter $directory is not a directory, the Boolean value FALSE is returned and an E_WARNING-level error is generated.
Example: view the contents of the demo directory:
This is the end of the article on "how PHP reads directories into an array". Thank you for reading! I believe you all have a certain understanding of "how to read the directory into the array by PHP". If you want to learn more, you are welcome to follow the industry information channel.