PHP数据排序的一个问题

帖子列表 发布于 2013/01/29 15:40
阅读 202
收藏 0
PHP


Array
(
    [3000005232] => Array
        (
            [0] => Array
                (
                    [MEMBER_ID] => 150502686
                    [DATE] => 13-01-03
                )

            [1] => Array
                (
                    [MEMBER_ID] => 150502686
                    [DATE] => 13-02-10
                )

            [2] => Array
                (
                    [MEMBER_ID] => 150502686
                    [DATE] => 13-03-10
                )

            [payment_status_1] => 1
            [payment_status_2] => 0
            [payment_status_3] => 0
            [comment] => 
        )

    [3000001393] => Array
        (
            [0] => Array
                (
                    [MEMBER_ID] => 150502042
                    [DATE] => 12-11-14
                )

            [1] => Array
                (
                    [MEMBER_ID] => 150502042
                    [DATE] => 12-12-10
                )

            [2] => Array
                (
                    [MEMBER_ID] => 150502042
                    [DATE] => 13-01-10
                )

            [payment_status_1] => 1
            [payment_status_2] => 0
            [payment_status_3] => 0
            [comment] => 
        )

    [3010000532] => Array
        (
            [0] => Array
                (
                    [MEMBER_ID] => 150502494
                    [DATE] => 12-12-19
                )

            [1] => Array
                (
                    [MEMBER_ID] => 150502494
                    [DATE] => 13-01-10
                )

            [2] => Array
                (
                    [MEMBER_ID] => 150502494
                    [DATE] => 13-02-10
                )

            [payment_status_1] => 1
            [payment_status_2] => 0
            [payment_status_3] => 0
            [comment] => 
        )
)



这是一个多维数组$arr,有三个键:3000005232,3000001393,3010000532,请根据每个键里面的第一个值即[0]里面的[DATE]进行排序,即如果[DATE]的值最小,比如这里3000001393里面的是12-11-14,那么将3000001393这个键和对应的值当做$arr的第一个元素,依次类推,请教大牛们怎么整这个排序?

这里贴出想要的结果:

Array
(
    [3000001393] => Array
        (
            [0] => Array
                (
                    [MEMBER_ID] => 150502042
                    [DATE] => 12-11-14
                )

            [1] => Array
                (
                    [MEMBER_ID] => 150502042
                    [DATE] => 12-12-10
                )

            [2] => Array
                (
                    [MEMBER_ID] => 150502042
                    [DATE] => 13-01-10
                )

            [payment_status_1] => 1
            [payment_status_2] => 0
            [payment_status_3] => 0
            [comment] => 
        )

    [3010000532] => Array
        (
            [0] => Array
                (
                    [MEMBER_ID] => 150502494
                    [DATE] => 12-12-19
                )

            [1] => Array
                (
                    [MEMBER_ID] => 150502494
                    [DATE] => 13-01-10
                )

            [2] => Array
                (
                    [MEMBER_ID] => 150502494
                    [DATE] => 13-02-10
                )

            [payment_status_1] => 1
            [payment_status_2] => 0
            [payment_status_3] => 0
            [comment] => 
        )

    [3000005232] => Array
        (
            [0] => Array
                (
                    [MEMBER_ID] => 150502686
                    [DATE] => 13-01-03
                )

            [1] => Array
                (
                    [MEMBER_ID] => 150502686
                    [DATE] => 13-02-10
                )

            [2] => Array
                (
                    [MEMBER_ID] => 150502686
                    [DATE] => 13-03-10
                )

            [payment_status_1] => 1
            [payment_status_2] => 0
            [payment_status_3] => 0
            [comment] => 
        )

)










加载中
0
Hobo
Hobo
function cmp($a, $b)
{
    $a = strtotime($a[0]['DATE']);
    $b = strtotime($b[0]['DATE']);
    if ($a == $b) {
        return 0;
    }
    return ($a < $b) ? -1 : 1;
}

uasort($arr, "cmp");

print_r($arr);
帖子列表
帖子列表
为什么你这么帅
帖子列表
帖子列表
为什么你这么帅
返回顶部
顶部