如何将数据合并,有哪个函数能用


合并成
class:”八年级10班”,
sign:27,
all_stu:51,
all_leave:1
求解

《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
最佳答案

写一个大概思想, 没 IDE 可能写错

$items = [];


$result = collect($items)->groupBy('class')->map(function($items, $key) {
      return [
        'class' => $key,
        'all_stu' => $items->sum('all_stu'),
        'all_leave'  => $items->sum('all_leave'),
        'sign' => $items->sum('sign'),
     ];
});
1年前 评论
讨论数量: 5

确定都是同一个 class 的话 array_merge()

1年前 评论

这个得看数据从何而来吧

1年前 评论

1,$a1 = array_merge([1,3], [1,4]) 2,$a1 = [1,4] + [1,3]

1年前 评论

写一个大概思想, 没 IDE 可能写错

$items = [];


$result = collect($items)->groupBy('class')->map(function($items, $key) {
      return [
        'class' => $key,
        'all_stu' => $items->sum('all_stu'),
        'all_leave'  => $items->sum('all_leave'),
        'sign' => $items->sum('sign'),
     ];
});
1年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!