I have this array

Array
(
[data] => Array
    (
        [0] => Array
            (

                [id] => 1293005125
                [viewed] => TRUE
                [active] => TRUE
                [time] => December 22, 2010 13:00 hours
                [timestamp] => 1293006034
                [initial_timestamp] => 1293005125
                [user] => administrator
            )

        [1] => Array
            (

                [mid] => 1293001908
                [viewed] => TRUE
                [active] => TRUE
                [time] => December 22, 2010 13:00 hours
                [timestamp] => 1293001908
                [initial_timestamp] => 1293001908
                [user] => administrator
            )

        [2] => Array
            (

                [mid] => 1293009999
                [viewed] => TRUE
                [active] => TRUE
                [time] => December 22, 2010 13:00 hours
                [timestamp] => 1293009999
                [initial_timestamp] => 1293009999
                [user] => administrator
            )

        [3] => Array
            (

                [mid] => 1293006666
                [viewed] => TRUE
                [active] => TRUE
                [time] => December 22, 2010 13:00 hours
                [timestamp] => 1293006666
                [initial_timestamp] => 1293006666
                [user] => administrator
            )

        [4] => Array
            (

                [mid] => 1293005125
                [viewed] => TRUE
                [active] => TRUE
                [time] => December 22, 2010 13:00 hours
                [timestamp] => 1293006125
                [initial_timestamp] => 1293005125
                [user] => administrator2
            )


    )

Now I would like to sort this array by [mid] How do I do this?

Currently I sort this in a foreach loop
There has to be a better way

EDIT I hoped to output something like

[mid] key => array value

Thanks

Comments

Accepted Answer

You can use the usort function.

usort($arr, "cmp");
function cmp($a, $b) {
        return $a["mid"] - $b["mid"];
}

See it

Written by codaddict
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki