🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[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(); ~~~