How to sort a multidimensional array by a certain key?

//define a comparison function
function cmp($a, $b) {
    if ($a['status'] == $b['status']) {
        return 0;
    }
    return ($a['status'] < $b['status']) ? -1 : 1;
}

usort($array, "cmp");

That should do what you want, you can alter the comparison function to sort on whatever key you want.

Leave a Comment