-3

event我想从一组玩家 id 的数组中找出最大值。有两组玩家 id 10125 和 10132。

我有一个数组,如下所示:

Array
(
[0] => Array
    (
        [event] => 200
        [playerid] => 10125
        [session] => 23131885ccc560bb6c8ead02eb4919c1
    )

[1] => Array
    (
        [event] => 199
        [playerid] => 10125
        [session] => 23131885ccc560bb6c8ead02eb4919c1
    )

[2] => Array
    (
        [event] => 198
        [playerid] => 10125
        [session] => 23131885ccc560bb6c8ead02eb4919c1
    )

[3] => Array
    (
        [event] => 197
        [playerid] => 10125
        [session] => 23131885ccc560bb6c8ead02eb4919c1
    )

[4] => Array
    (
        [event] => 196
        [playerid] => 10125
        [session] => 23131885ccc560bb6c8ead02eb4919c1
    )

[5] => Array
    (
        [event] => 31
        [playerid] => 10132
        [session] => 5a87375972ab4734e600c2dc1cec2ded
    )

[6] => Array
    (
        [event] => 30
        [playerid] => 10132
        [session] => 5a87375972ab4734e600c2dc1cec2ded
    )

[7] => Array
    (
        [event] => 29
        [playerid] => 10132
        [session] => 5a87375972ab4734e600c2dc1cec2ded
    )

[8] => Array
    (
        [event] => 28
        [playerid] => 10132
        [session] => 5a87375972ab4734e600c2dc1cec2ded
    )

[9] => Array
    (
        [event] => 29
        [playerid] => 10132
        [session] => 5a87375972ab4734e600c2dc1cec2ded
    )

[10] => Array
    (
        [event] => 28
        [playerid] => 10132
        [session] => 5a87375972ab4734e600c2dc1cec2ded
    )

[11] => Array
    (
        [event] => 28
        [playerid] => 10132
        [session] => 5a87375972ab4734e600c2dc1cec2ded
    )

[12] => Array
    (
        [event] => 27
        [playerid] => 10132
        [session] => 5a87375972ab4734e600c2dc1cec2ded
    )

[13] => Array
    (
        [event] => 26
        [playerid] => 10132
        [session] => 5a87375972ab4734e600c2dc1cec2ded
    )

[14] => Array
    (
        [event] => 25
        [playerid] => 10132
        [session] => 5a87375972ab4734e600c2dc1cec2ded
    )

[15] => Array
    (
        [event] => 24
        [playerid] => 10132
        [session] => 5a87375972ab4734e600c2dc1cec2ded
    )

[16] => Array
    (
        [event] => 23
        [playerid] => 10132
        [session] => 5a87375972ab4734e600c2dc1cec2ded
    )

[17] => Array
    (
        [event] => 25
        [playerid] => 10132
        [session] => 5a87375972ab4734e600c2dc1cec2ded
    )

[18] => Array
    (
        [event] => 24
        [playerid] => 10132
        [session] => 5a87375972ab4734e600c2dc1cec2ded
    )

[19] => Array
    (
        [event] => 23
        [playerid] => 10132
        [session] => 5a87375972ab4734e600c2dc1cec2ded
    )

[20] => Array
    (
        [event] => 22
        [playerid] => 10132
        [session] => 5a87375972ab4734e600c2dc1cec2ded
    )

[21] => Array
    (
        [event] => 21
        [playerid] => 10132
        [session] => 5a87375972ab4734e600c2dc1cec2ded
    )

[22] => Array
    (
        [event] => 20
        [playerid] => 10132
        [session] => 5a87375972ab4734e600c2dc1cec2ded
    )

[23] => Array
    (
        [event] => 19
        [playerid] => 10132
        [session] => 5a87375972ab4734e600c2dc1cec2ded
    )

[24] => Array
    (
        [event] => 18
        [playerid] => 10132
        [session] => 5a87375972ab4734e600c2dc1cec2ded
    )

[25] => Array
    (
        [event] => 1
        [playerid] => 10132
        [session] => 5a87375972ab4734e600c2dc1cec2ded
    )

)

所以结果像

[0] => Array
 (
    [event] => 200
    [playerid] => 10125
    [session] => 23131885ccc560bb6c8ead02eb4919c1
 )

[5] => Array
(
    [event] => 31
    [playerid] => 10132
    [session] => 5a87375972ab4734e600c2dc1cec2ded
)
4

1 回答 1

0

您可以将数组从高到低排序,然后抓取第一项......

function cmp($a, $b)
{
    if ($a->playerId == $b->playerId) {
        return 0;
    }
    return ($a->playerId > $b->playerId) ? -1 : 1;
}

usort($array, "cmp");
于 2013-01-04T11:30:20.923 回答