/**
* @description:根据数据
* @param {dataArr:需要分组的数据;keyStr:分组依据}
* @return: array
*/
protected function dataGroup(array $dataArr,$keyStr)
{
$newArr=[];
foreach ($dataArr as $k => $val) { //数据根据日期分组
$newArr[$val[$keyStr]][] = $val;
}
return $newArr;
}
$list = array(
array(
'ctime'=>'2019-09-05 15:12:11',
'openid'=>'1',
),
array(
'ctime'=>'2012-09-05 15:12:11',
'openid'=>'2',
),
);
/** 1.根据时间分组*/
$list= $this->dataGroup($list,'ctime');
/** 2.根据openid分组*/
foreach($list as $k => $item){
$list[$k]= $this->dataGroup($item,'openid');
}
/**
json $list
{
2019-09-05 15:12:11:{
1:{
'ctime':'2019-09-05 15:12:11',
'openid':'1',
}
},
2012-09-05 15:12:11:{
2:{
'ctime':'2012-09-05 15:12:11',
'openid':'2',
}
}
}
**/
网友评论