Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Dano Stuporstar

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

php glob_rsort_modtime()

   1  
   2  <?php
   3  /**
   4   FUNCTION: glob_rsort_modtime()
   5   * Glob reverse sorted by file modification time.
   6   *
   7   * Returns an array of files matching the given glob pattern, sorted 
   8   * by their modification times in descending order.  The array keys
   9   * hold the filepath and the values hold the mtime.  On error, array
  10   * will be indexed and contain 'false' and an error message.
  11   *
  12   * {@source}
  13   *
  14   * @param string $patt Pattern to search, including glob braces.
  15   * @return array filename => mtime OR false, 'errormsg'.
  16   */
  17  function glob_rsort_modtime( $patt ) {
  18      if ( ( $files = @glob($patt, GLOB_BRACE) ) === false ) {
  19          return array( false, 'Glob error.');
  20      }
  21      if ( !count($files) ) {
  22          return array( false, 'No files found.');
  23      }
  24      $rtn = array();
  25      foreach ( $files as $filename ) {
  26          $rtn[$filename] = filemtime($filename);
  27      }
  28      arsort($rtn);
  29      reset($rtn);
  30      return $rtn;
  31  }
  32  
  33  $files = glob_rsort_modtime( './*' ) ;
  34  echo'<pre>'.print_r($files, true).'</pre>';
  35  ?> 
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS