laravel 中的 mapWithKeys,我不明白它是如何工作的?

mapWithKeys in laravel ,i dont understand how do it work?

我看到了 laravel 的例子,但我不明白它是如何工作的。

对于 this example:

$collection = collect([
    [
        'name' => 'John',
        'department' => 'Sales',
        'email' => 'john@example.com'
    ],
    [
        'name' => 'Jane',
        'department' => 'Marketing',
        'email' => 'jane@example.com'
    ]
]);

$keyed = $collection->mapWithKeys(function ($item) {
    return [$item['email'] => $item['name']];
});

$keyed->all();

谁能详细解释一下?

$collection = collect([
    [
        'name' => 'John',
        'department' => 'Sales',
        'email' => 'john@example.com'
    ],
    [
        'name' => 'Jane',
        'department' => 'Marketing',
        'email' => 'jane@example.com'
    ]
]);

$keyed = $collection->mapWithKeys(function ($item) {
   //this line takes one array of collection object in item array and  make a key of its email and store name on that email key  
    return [$item['email'] => $item['name']];
});

$keyed->all();