-2

I have a multi-dimensional array like so.

[0] => Array
    (
        [time] => 1312206805
        [item] => email@example.net created ad ad.
    )

[1] => Array
    (
        [time] => 1312206805
        [item] => email@example.net created an ad.
    )

[2] => Array
    (
        [time] => 1312130982
        [item] => info@example.org created an ad.
    )

I'd like to sort by the time, while maintaining indexes and keeping each parent array together.

ndmweb
  • 3,370
  • 6
  • 33
  • 37
  • 3
    Please check your older questions and accepted correct answers. Community helps you. Why you don't help community ? – RiaD Aug 01 '11 at 20:09
  • possible duplicate of [Sorting a multidimensional array in PHP?](http://stackoverflow.com/questions/1795244/sorting-a-multidimensional-array-in-php) ... or one of other dozens like it on SO... just use `uasort`. – Wrikken Aug 01 '11 at 20:10

1 Answers1

3
uasort($arr,function($a,$b){
    return $a['time'] - $b['time'];
});

Requires php5.3+
If you use older version you can replace anonymous function by other callback

RiaD
  • 46,822
  • 11
  • 79
  • 123