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); }