Skip to content

Commit

Permalink
Use array_merge spread to increase speed and decrease memory usage
Browse files Browse the repository at this point in the history
  • Loading branch information
bastien-phi committed Dec 15, 2023
1 parent 62fb709 commit c53eb64
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Illuminate/Collections/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,17 @@ public static function divide($array)
*/
public static function dot($array, $prepend = '')
{
$results = [];
$results = [[]];

foreach ($array as $key => $value) {
if (is_array($value) && ! empty($value)) {
$results += static::dot($value, $prepend.$key.'.');
$results[] = static::dot($value, $prepend.$key.'.');
} else {
$results[$prepend.$key] = $value;
$results[0][$prepend.$key] = $value;
}
}

return $results;
return array_merge(...$results);
}

/**
Expand Down

0 comments on commit c53eb64

Please sign in to comment.