In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how to sort php files by modification time, which has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
Php files are sorted by modification time: 1, through the "function printdir ($dir) {...}" method to traverse the files under the directory; 2, through the "function arraysort ($aa) {...}" method to sort the returned array by modification time.
This article operating environment: Windows7 system, PHP7.4 version, Dell G3 computer.
Example of php traversing files in a directory and sorting by modification time
Php traverses the files under the directory:
/ / traverse the file method function printdir ($dir) {$files = array () under the directory / / opendir () Open the directory handle if ($handle = @ opendir ($dir)) {/ / readdir () from the directory handle (resource Previously opened by opendir () to read entries, / / if not, return false while (($file = readdir ($handle))! = = false) {/ / read entry if ($file! = ".." & $file! = ".") {/ / exclude the root directory if (is_dir ($dir. "/". $file) {/ / if file is a directory, recursive $files [$file] = printdir ($dir. "/". $file);} else {/ / get the file modification date $filetime = date ('Y-m-d Hlav ifiletime slots, filemtime ($dir.) "/". $file); / / File modification time as a healthy value $files [$filetime] = $file;} @ closedir ($handle); return $files;}}
Sort the returned array by time
/ / sort the array by modification time function arraysort ($aa) {if (is_array ($aa)) {ksort ($aa); foreach ($aa as $key = > $value) {if (is_array ($value)) {$arr [$key] = arraysort ($value);} else {$arr [$key] = $value }} return $arr;} else {return $aa;}} $dir = "/ php"; / / output all files under / php print_r (arraysort (printdir ($dir) Thank you for reading this article carefully. I hope the article "how to sort php files by modification time" shared by the editor will be helpful to everyone. At the same time, I also hope you can support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
This article mainly introduces the ways of web form submission, which has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to know about it. Let's first take a look at several ways of form submission: 1.
Wechat
About us
Contact us
Product review
car news
thenatureplanet
More Form oMedia:
AutoTimes.
Bestcoffee.
SL News.
Jarebook.
Coffee Hunters.
Sundaily.
Modezone.
NNB.
Coffee.
Game News.
FrontStreet.
GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.