How do I sort a multidimensional array in php

1
2
3
4
5
6
7
8
9
10
11
12
13
function aasort (&$array, $key) {
    $sorter=array();
    $ret=array();
    reset($array);
    foreach ($array as $ii => $va) {
        $sorter[$ii]=$va[$key];
    }
    asort($sorter);
    foreach ($sorter as $ii => $va) {
        $ret[$ii]=$array[$ii];
    }
    $array=$ret;
}

Calling of function:
aasort($array,”datetime”);
passed field name and array

Leave a Reply