如何按此值对此数组进行排序?

时间:2013-08-02 13:28:39

标签: php

如何在PHP中对此数组进行排序?我想先把最近的日期。我无法在MySQL中进行排序,因为日期字段来自几个不同的表。这里显示了三行 - 总共超过600行。

Array
(
    [0] => Array
        (
        Translator => Array
            (
                [id] => 1482
                [name] => Jane Doe
                [last_project] => (null)
            )
        )

    [1] => Array
        (
        Translator => Array
            (
                [id] => 1024
                [name] => John Doe
                [last_project] => 2013-06-25
            )
        )

    [2] => Array
        (           
        Translator => Array
            (
                [id] => 32
                [name] => Tom Doe
                [last_project] => 2009-07-10
             )
        )
)

2 个答案:

答案 0 :(得分:2)

function sortFunction( $a, $b ) {
    return strtotime($a["last_project"]) - strtotime($b["last_project"]);
}
usort($array, "sortFunction");

取自PHP order array by date?

答案 1 :(得分:1)

function sortByDate($a, $b) {
    return $a['last_project'] - $b['last_project'];
}

usort($myArray, 'sortByDate');