按[类型]排序多维数组

时间:2013-01-29 11:52:47

标签: php arrays drupal multidimensional-array

如何按照类似视频然后简单页面的类型对此数组进行排序?

print_r($result);

输出:

Array
(
    [link] => http://localhost/test/test
    [type] => Video
    [title] => Treasurer Robot
    [date] => 1359397195
    [node] => stdClass Object
        (
            [nid] => 9
            [type] => video
            [language] => 
            [uid] => 1
            [status] => 1
            [created] => 1344351903
            [changed] => 1359397195
            [comment] => 0
            [promote] => 1
    )
)

Array
(
    [link] => http://localhost/test/test
    [type] => Simple Page
    [title] => Treasurer Robot2
    [date] => 1359397193
    [node] => stdClass Object
        (
            [nid] => 11
            [type] => Simple Page
            [language] => 
            [uid] => 1
            [status] => 1
            [created] => 1344351903
            [changed] => 1359397195
            [comment] => 0
            [promote] => 1
    )
)

Array
(
    [link] => http://localhost/test/test
    [type] => Video
    [title] => Treasurer Robot3
    [date] => 1359397195
    [node] => stdClass Object
        (
            [nid] => 19
            [type] => video
            [language] => 
            [uid] => 1
            [status] => 1
            [created] => 1344351903
            [changed] => 1359397195
            [comment] => 0
            [promote] => 1
    )
)

2 个答案:

答案 0 :(得分:0)

有许多php排序功能。请从下面的网址找到一个适合你的。 http://resource.gvignesh.org/use-the-power-of-these-php-functions-to-sort-your-arrays/

答案 1 :(得分:0)

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;
}
aasort($your_array,"order");