diff --git a/src/Illuminate/Collections/Arr.php b/src/Illuminate/Collections/Arr.php index d0544154e800..c14465c6b3fa 100644 --- a/src/Illuminate/Collections/Arr.php +++ b/src/Illuminate/Collections/Arr.php @@ -113,13 +113,13 @@ public static function dot($array, $prepend = '') foreach ($array as $key => $value) { if (is_array($value) && ! empty($value)) { - $results[] = static::dot($value, $prepend.$key.'.'); + $results = array_merge($results, static::dot($value, $prepend.$key.'.')); } else { - $results[] = [$prepend.$key => $value]; + $results[$prepend.$key] = $value; } } - return array_merge(...$results); + return $results; } /** diff --git a/tests/Support/SupportArrTest.php b/tests/Support/SupportArrTest.php index 3ff9851fab4c..083ca5bbb306 100644 --- a/tests/Support/SupportArrTest.php +++ b/tests/Support/SupportArrTest.php @@ -102,6 +102,12 @@ public function testDot() $array = Arr::dot(['foo' => ['bar' => 'baz']]); $this->assertSame(['foo.bar' => 'baz'], $array); + $array = Arr::dot([10 => 100]); + $this->assertSame([10 => 100], $array); + + $array = Arr::dot(['foo' => [10 => 100]]); + $this->assertSame(['foo.10' => 100], $array); + $array = Arr::dot([]); $this->assertSame([], $array);