【发布时间】:2013-06-10 11:28:10
【问题描述】:
如何将日期分组并计算权重总和然后放入 assoc 数组 php?
{name:"A",date:"2012-12-11",order:1,time:3,weight:10},
{name:"A",date:"2012-12-11",order:1,time:4,weight:12},
{name:"B",date:"2012-12-11",order:1,time:3,weight:17},
{name:"A",date:"2012-12-12",order:1,time:5,weight:50},
{name:"A",date:"2012-12-12",order:2,time:3,weight:70}
根据这个重量的总和一天一天,但问题是如果(相同日期相同订单相同名称;哪个更大的时间占其权重,不在乎)但不同的名称或订单占组的总和。
结果必须是这样的:
{date:2012-12-11,weight:29},
{date:2012-12-12,weight:120},
有人帮忙吗? 可以是这样的:
{name:"A",date:"2012-12-11",order:1,time:3,weight:10},
{name:"B",date:"2012-12-11",order:1,time:3,weight:17},
{name:"A",date:"2012-12-11",order:1,time:4,weight:12},
{name:"A",date:"2012-12-12",order:1,time:5,weight:50},
{name:"A",date:"2012-12-12",order:2,time:3,weight:70}
【问题讨论】:
-
{date:2012-12-11,weight:29},应该是 {date:2012-12-11,weight:39} ..不是吗??
-
不需要29,因为同名同日同订单。
-
我们将选出他们之间时间最长的人。
标签: php json sorting compare grouping