Skip to content

Commit

Permalink
[10.x] Fixes the Arr::dot() method to properly handle indexes array (
Browse files Browse the repository at this point in the history
…#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]>
  • Loading branch information
kayw-geek and crynobone authored Dec 28, 2023
1 parent ac960a1 commit bd9b41e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Illuminate/Collections/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
6 changes: 6 additions & 0 deletions tests/Support/SupportArrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit bd9b41e

Please sign in to comment.