ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
原始数据中 ~~~ “table_name”:字段所属表 “field_name“ : 字段名 “field_col_num":字段排序号 ~~~ 期待输出的结果是 ~~~ { "table_name" : [ "field_name", "field_name", .... ] } ~~~ 原始数据: ``` [ { "table_name": "dp", "field_name": "dpcryptfeat", "field_col_num": "6" }, { "table_name": "dp", "field_name": "dppath", "field_col_num": "4" }, { "table_name": "dp", "field_name": "dpauthfeat", "field_col_num": "5" }, { "table_name": "dp", "field_name": "dpnick", "field_col_num": "3" }, { "table_name": "icc", "field_name": "iccbufsizeprot", "field_col_num": "13" }, { "table_name": "icc", "field_name": "iccmech", "field_col_num": "5" }, { "table_name": "icc", "field_name": "iccnick", "field_col_num": "3" }, { "table_name": "icc", "field_name": "iccprocmanager", "field_col_num": "8" }, { "table_name": "icc", "field_name": "iccdesc", "field_col_num": "4" }, { "table_name": "icc", "field_name": "iccprot", "field_col_num": "6" }, { "table_name": "icc", "field_name": "iccformatprot", "field_col_num": "14" } ] ``` 输出结果: ~~~ { "dp": [ "dpnick", "dppath", "dpauthfeat", "dpcryptfeat" ], "icc": [ "iccnick", "iccdesc", "iccmech", "iccprot", "iccprocmanager", "iccbufsizeprot", "iccformatprot" ] } ~~~ # 解决一 ~~~ dd(collect(json_decode($input))->groupBy('table_name')->map(function($item){ return collect($item)->sortBy('field_col_num')->map(function($data) { return $data->field_name; })->values(); })->toJson()); ~~~ # 解决二 ~~~ collect($groups)->sortBy('field_col_num')->groupBy('table_name')->map(function ($group) { return $group->pluck('field_name'); }); ~~~