0

Say I have the following array, how can I sort it on sort_by?

Array
(
    [10] => Array
        (
            [Masthead_slide] => Array
                (
                    [id] => 1456464564
                    [sort_by] => 1
                )

        )

    [6] => Array
        (
            [Masthead_slide] => Array
                (
                    [id] => 645454
                    [sort_by] => 10
                )

        )

    [7] => Array
        (
            [Masthead_slide] => Array
                (
                    [id] => 4547
                    [sort_by] => 5
                )

        )
)
Dan
  • 11,914
  • 14
  • 49
  • 112
  • Especially [this answer](http://stackoverflow.com/questions/17364127/reference-all-basic-ways-to-sort-arrays-and-data-in-php/17364128#17364128) – Wrikken Aug 19 '14 at 16:12

1 Answers1

1

Try by this

function sortByOrder($a, $b) {
    return $a['sort_by'] - $b['sort_by'];
}
usort($arr, 'sortByOrder');
MH2K9
  • 11,951
  • 7
  • 32
  • 49