数组根据下标进行归类
作者:互联网
$a = [
['id'=>1,'title'=>'星期二的早晨','author'=>'张三','date'=>'2021-6-1'],
['id'=>2,'title'=>'星期三的早晨','author'=>'李四','date'=>'2021-6-1'],
['id'=>3,'title'=>'星期四的早晨','author'=>'王五','date'=>'2021-6-2']
];
$arr = [];
foreach ($a as $v){
$arr[$v['date']] = [
'date'=>$v['date'],
'articles'=>[]
];
}
foreach ($a as $v){
$arr[$v['date']]['articles'][] = $v;
}
return json($arr);
标签:arr,下标,author,title,归类,2021,数组,date,id 来源: https://www.cnblogs.com/ccdr/p/14836606.html