关于Collection的一道小题

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

我这边的测试结果是:

array:3 [▼
  1 => array:5 [▼
    "AAA" => 1
    "BBB" => 2
    "CCC" => 3
    "DDD" => 4
    "EEE" => 5
  ]
  2 => array:5 [▼
    "AAA" => 6
    "BBB" => 7
    "CCC" => 8
    "DDD" => 9
    "EEE" => 10
  ]
  3 => array:5 [▼
    "AAA" => 11
    "BBB" => 12
    "CCC" => 13
    "DDD" => 14
    "EEE" => 15
  ]
]
JellyBool
修改的评论也不能少于六个字哦!
javascript 回复 JellyBool
修改的评论也不能少于六个字哦!
JellyBool 回复 javascript
修改的评论也不能少于六个字哦!
javascript
修改的评论也不能少于六个字哦!