Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How php files are sorted by modification time

2025-03-28 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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report