From c09a0fdb92a4aa42552723b2238713bc9a9b1adb Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sun, 14 Jan 2018 09:00:04 -0600 Subject: [PATCH] use foreach --- src/Illuminate/Support/Collection.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Support/Collection.php b/src/Illuminate/Support/Collection.php index 9b4dc4acbccf..ca87db9e64cc 100644 --- a/src/Illuminate/Support/Collection.php +++ b/src/Illuminate/Support/Collection.php @@ -884,16 +884,19 @@ public function mapToDictionary(callable $callback) { $dictionary = []; - $this->each(function ($item, $key) use (&$dictionary, $callback) { + foreach ($this->items as $key => $item) { $pair = $callback($item, $key); + $key = key($pair); + $value = reset($pair); if (! isset($dictionary[$key])) { $dictionary[$key] = []; } + $dictionary[$key][] = $value; - }); + } return new static($dictionary); }