企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# mapWithKeys方法 遍历集合并将每个值传入给定的回调。回调应该返回包含一个键值对的关联数组 ``` $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(); /* [ 'john@example.com' => 'John', 'jane@example.com' => 'Jane', ] */ ```