【发布时间】:2015-07-30 08:52:15
【问题描述】:
这是我的数组。
Array(
[0] => Array
(
[amt] => 50.00
[transaction_date] => 2015-07-18
)
[1] => Array
(
[amt] => 0.00
[transaction_date] => 2015-07-17
)
[2] => Array
(
[amt] => 60.00
[transaction_date] => 2015-07-18
)
)
我正在尝试根据日期对数组进行排序或分组。交易日期应该是一个意味着数组中没有重复的交易条目。
我想要新的数组如下
Array(
[0] => Array
(
[amt] => 110.00
[transaction_date] => 2015-07-18
)
[1] => Array
(
[amt] => 0.00
[transaction_date] => 2015-07-17
)
)
2015-07-18 此日期在数组中出现 2 次,应根据重复添加 2 个不同的数量。金额应为 110
$temp=0;
$ctr=0;
for($i=0;$i<count($new_data);$i++)
{
$temp=$new_data[$i]['transaction_date'];
for($j=0;$j<=$i;$j++)
{
if($temp==$new_data[$j]['transaction_date'])
{
$newarray[][$new_data[$j]['transaction_date']]=++$ctr;
}
}
$ctr=0;
}
print_r($newarray);
【问题讨论】: