ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

sort array by value

January 05, 2009 5:59am

Subscribe [2]
  • #1 / Jan 05, 2009 5:59am

    hugle

    289 posts

    Hello all.

    Don’t know how to correctly describe the situation, but I try:

    I have an array $threats with data in it:

    for example to get the latest posts time, I do:

    for($i=0;$i<count($threats);$i++) {
    echo $threats[$i]['last_post'];
    }
         
    How I can sort this array by $threats[$i][‘last_post’] ?

    how is it achieved?
    I somehow can’t find the solution for it.

    Thank you very much!

  • #2 / Jan 05, 2009 6:36am

    Tom Schlick

    386 posts

    if im understanding you correctly then the ksort() function should do the trick

    http://us.php.net/ksort

  • #3 / Jan 05, 2009 3:51pm

    Michael Wales

    2070 posts

    I assume you are pulling this data from a database - the optimal solution would be to sort at the database layer.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases