我有一个包含这些值的数组:
Array
(
[0] => Array
(
[0] => John
[1] => 2012-03-29
[2] => 1
)
[1] => Array
(
[0] => Doe
[1] => 2012-03-30
[2] => 1
)
[2] => Array
(
[0] => John
[1] => 2012-03-31
[2] => 2
)
[3] => Array
(
[0] => Doe
[1] => 2012-03-31
[2] => 5
)
[4] => Array
(
[0] => John
[1] => 2012-04-02
[2] => 5
)
[5] => Array
(
[0] => John
[1] => 2012-04-02
[2] => 21
)
)
array[][2]
我正在尝试获取中每个日期的最大值array[][1]
。
例如,在数组中
Array[2][1] = 2012-03-31 | Array[2][2] = 2
Array[3][1] = 2012-03-31 | Array[3][2] = 5
这两天我想保留Array[3]
和丢弃Array[2]
。
我尝试了一个 foreach 函数:
foreach ($days as $k) {
$max_vals[] = array($k[0], $k[1], max($k[2]));
}
却发现那是不行的日子。如何对这个数组进行排序,保持每天的最高值,然后丢弃其余的?