ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[TOC] # 问题一 ~~~ $table = [ ['AAA', 'BBB', 'CCC', 'DDD', 'EEE'], [1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15] ]; ~~~ 将上面的配列转化成为: ~~~ [ [ "AAA"=> 1, "BBB"=> 2, "CCC"=> 3, "DDD"=> 4, "EEE"=> 5 ], [ "AAA"=> 6, "BBB"=> 7, "CCC"=> 8, "DDD"=> 9, "EEE"=> 10 ], [ "AAA"=> 11, "BBB"=> 12, "CCC"=> 13, "DDD"=> 14, "EEE"=> 15 ] ] ~~~ # 解决一 ~~~ $table = [ ['AAA', 'BBB', 'CCC', 'DDD', 'EEE'], [1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15] ]; $records = collect($items)->except(0)->map(function ($item) use ($table){ return collect($item)->combine(collect($table)->first())->flip(); })->toArray(); ~~~ # 解决二 ~~~ $table = [ ['AAA', 'BBB', 'CCC', 'DDD', 'EEE'], [1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15] ]; $records = collect($items)->except(0)->map(function ($item) use ($table){ return collect($item)->combine(collect($table)->first())->flip(); })->toArray(); ~~~