How would I list the first 5 files or directories in directory sorted alphabetically with PHP?
How would I list the first 5 files or directories in directory sorted alphabetically
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Using
scandir():The
array_filter()together with theis_file()function callback makes sure we just process files without having to write a loop, we don’t even have to care about.and..as they are directories.Or using
glob()– it won’t match filenames like.htaccess:Or using
glob()+array_filter()– this one will match filenames like.htaccess: