php页面 数组根据下标来排序

$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);

 

posted on 2021-06-12 11:59  棍棍的爱情  阅读(98)  评论(0编辑  收藏  举报