Skip to content

Commit

Permalink
use foreach
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jan 14, 2018
1 parent 337e0e8 commit c09a0fd
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Illuminate/Support/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit c09a0fd

Please sign in to comment.