我有一个这样的数组:
$data = array (
0 =>
array (
'UserID' => '1',
'ShipPinCode' => '411008',
'createdDate' => '2011-10-04 01:16:54.723',
'Amount' => '1000.00',
),
1 =>
array (
'UserID' => '1',
'ShipPinCode' => '411008',
'createdDate' => '2011-10-04 01:24:24.243',
'Amount' => '1000.00',
),
2 =>
array (
'UserID' => '102818',
'ShipPinCode' => '500072',
'createdDate' => '2011-11-29 12:17:43.880',
'Amount' => '2000.00',
),
3 =>
array (
'UserID' => '100001',
'ShipPinCode' => '500072',
'createdDate' => '2011-11-26 11:49:17.760',
'Amount' => '2000.00',
),
);
我想以这样一种方式对其进行排序,即对于 UserID 的重复条目,最终输出应该只包含该 UserID 的一行,其中 createdDate 是最大的,即按降序排列。
期望的输出:
array (
0 =>
array (
'UserID' => '1',
'ShipPinCode' => '411008',
'createdDate' => '2011-10-04 01:24:24.243', //only took one row of UserID 1 where the createdDate is the largest.
'Amount' => '1000.00',
),
1 =>
array (
'UserID' => '102818',
'ShipPinCode' => '500072',
'createdDate' => '2011-11-29 12:17:43.880',
'Amount' => '2000.00',
),
2 =>
array (
'UserID' => '100001',
'ShipPinCode' => '500072',
'createdDate' => '2011-11-26 11:49:17.760',
'Amount' => '2000.00',
),
);
在这种情况下,我无法弄清楚如何进行比较。我该怎么做?