filter scandir and sort by date created

前端 未结 2 1255
感动是毒
感动是毒 2021-02-11 01:39
  1. I need to get the files in a directory in an array.
    • Only files that end in .markdown
  2. The files should be sorted by date created

2条回答
  •  面向向阳花
    2021-02-11 02:09

    Easiest way to get the file list is simply do

    $files = glob('*.markdown');
    

    glob() basically does the same kind of wildcard matching that occurs at a shell prompt.

    Sorting by date will require you to look at each of those files with stat() and retrieve its mtime/ctime/atime values (which fileatime(), filemtime(), filectime() return directly, but still use stat() internally).

提交回复
热议问题