Sort array by date....

Discussion in 'PHP' started by jkashu, May 12, 2008.

  1. #1
    I have a bunch of dates into an array from a text file. How do I sort the array by date?

    Thanks!
     
    jkashu, May 12, 2008 IP
  2. cornetofreak

    cornetofreak Peon

    Messages:
    170
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #2
    usort my help here

    EG

    <?php
    
    $dates= array("date1", "date2", "date3", "date4");
    sort($dates);
    foreach ($dates as $key => $val) {
        echo "Dates[" . $key . "] = " . $val . "\n";
    }
    
    ?>
    PHP:
    somthing like this anyway
     
    cornetofreak, May 12, 2008 IP
  3. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #3
    What format is the date in?

    Sort will not work.

    Peace,
     
    Barti1987, May 12, 2008 IP
  4. cornetofreak

    cornetofreak Peon

    Messages:
    170
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #4
    this was an example off php . net look at usort in there you can find it all out
     
    cornetofreak, May 12, 2008 IP
  5. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #5
    The code you posted had sort, that is what I said it won't work.

    You are correct, Usort will work, however, you still need to write a function to compare values, which is why I asked for the format of the date.

    PEace,
     
    Barti1987, May 12, 2008 IP
  6. jkashu

    jkashu Peon

    Messages:
    39
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    The date is in this format: 10 Apr 2008, 9:42 am
    Thanks!
     
    jkashu, May 12, 2008 IP