$result= array();
//$dataList是你要遍历的数组
foreach ($dataList as $key => $info) {
$result[$info['valid_period']]["day"]=$info['valid_period'];
$result[$info['valid_period']]["array"][]=$info;
}
//array_values($result)这是为了去掉健值生成数字健值
$data["dataList"] =array_values($result);
//结果
//认真看你就能懂了,很简单的。
"dataList": [
{
"day": "7",
"array": [
{
"id": "93",
"valid_period": "7",
"data": "1024.00",
"plan_name": "China 1GB 7days"
},
{
"id": "94",
"valid_period": "7",
"data": "2048.00",
"plan_name": "China 2GB 7days"
}
]
},
{
"day": "30",
"array": [
{
"id": "98",
"valid_period": "30",
"data": "1024.00",
"plan_name": "China 1GB 30days"
},
{
"id": "99",
"valid_period": "30",
"data": "2048.00",
"plan_name": "China 2GB 30days"
},
]
},
{
"day": "90",
"array": [
{
"id": "110",
"valid_period": "90",
"data": "10240.00",
"plan_name": "China 10GB 90days"
},
{
"id": "111",
"valid_period": "90",
"data": "15360.00",
"plan_name": "China 15GB 90days"
}
}
]
},