0
Array
(
    [0] => Array
        (
            [id] => 17
            [uid] => 54915a9f4f26e
            [unixtimestamp] => 1408210200
        )

    [1] => Array
        (
            [id] => 26
            [uid] => 54915a9f519a2
            [unixtimestamp] => 1408815000
        )

)

This is my array, I want to sort them by unixtimestamps orded.

How can I tell PHP sort function that I want to sort the specific unixtimestamp element?

sort($myarray); // how to tell sort by unixtimestamp?
Badr Hari
  • 8,114
  • 18
  • 67
  • 100

1 Answers1

3

Use usort()

function sortByOrder($a, $b) {
  return $a['unixtimestamp'] - $b['unixtimestamp'];
}

usort($myArray, 'sortByOrder');

Where $myArray is your array

Pupil
  • 23,834
  • 6
  • 44
  • 66