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
                )

        )
)
1

1 Answer 1

1

Try by this

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.