Skip to content

Commit bd9b41e

Browse files
kayw-geekcrynobone
andauthored
[10.x] Fixes the Arr::dot() method to properly handle indexes array (#49507)
* Fixes the `Arr::dot()` method to properly handle arrays with integer keys * Update tests/Support/SupportArrTest.php Co-authored-by: Mior Muhammad Zaki <[email protected]> --------- Co-authored-by: Mior Muhammad Zaki <[email protected]>
1 parent ac960a1 commit bd9b41e

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/Illuminate/Collections/Arr.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,13 @@ public static function dot($array, $prepend = '')
113113

114114
foreach ($array as $key => $value) {
115115
if (is_array($value) && ! empty($value)) {
116-
$results[] = static::dot($value, $prepend.$key.'.');
116+
$results = array_merge($results, static::dot($value, $prepend.$key.'.'));
117117
} else {
118-
$results[] = [$prepend.$key => $value];
118+
$results[$prepend.$key] = $value;
119119
}
120120
}
121121

122-
return array_merge(...$results);
122+
return $results;
123123
}
124124

125125
/**

tests/Support/SupportArrTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ public function testDot()
102102
$array = Arr::dot(['foo' => ['bar' => 'baz']]);
103103
$this->assertSame(['foo.bar' => 'baz'], $array);
104104

105+
$array = Arr::dot([10 => 100]);
106+
$this->assertSame([10 => 100], $array);
107+
108+
$array = Arr::dot(['foo' => [10 => 100]]);
109+
$this->assertSame(['foo.10' => 100], $array);
110+
105111
$array = Arr::dot([]);
106112
$this->assertSame([], $array);
107113

0 commit comments

Comments
 (0)