4

我有一个这样的数组,

array[0][0],[1][0],[2][0] 是问题,array[0][1],[1][1],[2][1] 是答案问题。
现在我想根据答案的数量对这个数组进行排序。
第一个问题只有一个答案,第二个问题有两个答案,第三个问题有三个答案。
排序后的数组应该按照该问题的答案数量降序排列。无论如何在sql中实现这一点?或者我们如何在php中排序?希望我的问题很清楚。先感谢您。

Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [0] => 12
                    [1] => 110
                    [2] => Tom
                    [3] => Tom@gmail.com
                    [4] => Hello tom how are you?
                    [5] => 2013-01-03 14:54:07
                )

            [1] => Array
                (
                    [0] => Array
                        (
                            [0] => 12
                            [1] => Yes i am fine.
                            [2] => Arun
                            [3] => arun@gmail.com
                            [4] => 2013-01-03 14:55:22
                        )
                )
        )
    [1] => Array
        (
            [0] => Array
                (
                    [0] => 12
                    [1] => 110
                    [2] => Tom
                    [3] => Tom@gmail.com
                    [4] => Hello tom how are you.
                    [5] => 2013-01-03 14:54:07
                )

            [1] => Array
                (
                    [0] => Array
                        (
                            [0] => 12
                            [1] => Yes i am fine
                            [2] => Arun
                            [3] => arun@gmail.com
                            [4] => 2013-01-03 14:55:22
                        )
                    [1] => Array
                        (
                            [0] => 12
                            [1] => Yes i am fine
                            [2] => Arun
                            [3] => arun@gmail.com
                            [4] => 2013-01-03 14:55:22
                        )
                )
        )
    [2] => Array
        (
            [0] => Array
                (
                    [0] => 12
                    [1] => 110
                    [2] => Tom
                    [3] => Tom@gmail.com
                    [4] => Hello tom how are you.
                    [5] => 2013-01-03 14:54:07
                )
            [1] => Array
                (
                    [0] => Array
                        (
                            [0] => 12
                            [1] => Yes i am fine
                            [2] => Arun
                            [3] => arun@gmail.com
                            [4] => 2013-01-03 14:55:22
                        )
                    [1] => Array
                        (
                            [0] => 12
                            [1] => Yes i am fine
                            [2] => Arun
                            [3] => arun@gmail.com
                            [4] => 2013-01-03 14:55:22
                        )
                [2] => Array
                        (
                            [0] => 12
                            [1] => Yes i am fine
                            [2] => Arun
                            [3] => arun@gmail.com
                            [4] => 2013-01-03 14:55:22
                        )
                )
        )
4

1 回答 1

4

这应该有效:

function cmp($a, $b)
{
    return count($a[1]) > count($b[1]) ? -1 : 1;
}

usort($data, 'cmp');

或者,如果您正在使用PHP 5.3.0或更高版本,您可以使用:

usort($data, function ($a, $b) {
    return count($a[1]) > count($b[1]) ? -1 : 1;
});
于 2013-01-04T05:59:20.850 回答