SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2002
    Location
    New Zealand
    Posts
    168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    reading dir, arranging by newest

    Hi there,
    I am using this code created by SpikeZ to list a content of a directory.

    PHP Code:
    $the_array = Array(); 
    $handle opendir('/usr/'); 
    while (
    false !== ($file readdir($handle))) { 
    if (
    $file != "." && $file != "..") { /* as descripted below: these "files" will not be added to the array */ 
    $the_array[] = $file


    closedir($handle); 
    foreach (
    $the_array as $element) { 
    echo 
    "$element"
    echo 
    '<br>'

    But now, I was wondering, is there a way to arrage the output by the newest file(eg, arrange by the Date of Creation)? and also high light it in bold?

  2. #2
    SitePoint Wizard Chris82's Avatar
    Join Date
    Mar 2002
    Location
    Osnabrück
    Posts
    1,003
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is a solution for sorting files. (posted it )

    http://www.sitepoint.com/forums/show...51&postcount=2

  3. #3
    SitePoint Zealot Koobi's Avatar
    Join Date
    Nov 2003
    Location
    Sri Lanka
    Posts
    156
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Another way I could think of would be to read the filemtime() of that file while reading the filename itself in the while loop (best if you read both name and filemtime into one array) and then using array_multisort() to sort the array by time.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •