diff --git a/src/Helpers/Arr.php b/src/Helpers/Arr.php index bd83f3f..96fc84f 100644 --- a/src/Helpers/Arr.php +++ b/src/Helpers/Arr.php @@ -8,7 +8,7 @@ * * @author Andrey Helldar * - * @copyright 2024 Andrey Helldar + * @copyright 2025 Andrey Helldar * * @license MIT * @@ -154,7 +154,7 @@ public function sortByKeys(array|ArrayObject $array, array $sorter): array { $sorter = array_intersect($sorter, array_keys($array)); - return array_merge(array_flip($sorter), $array); + return $this->merge(array_flip($sorter), $array); } /** @@ -542,7 +542,7 @@ public function flattenKeys(mixed $array, string $delimiter = '.', ?string $pref if (is_array($value)) { $values = $this->flattenKeys($value, $delimiter, $new_key); - $result = array_merge($result, $values); + $result = $this->merge($result, $values); continue; } diff --git a/tests/Unit/Helpers/Arr/FlattenKeysTest.php b/tests/Unit/Helpers/Arr/FlattenKeysTest.php index 0fb7171..9299147 100644 --- a/tests/Unit/Helpers/Arr/FlattenKeysTest.php +++ b/tests/Unit/Helpers/Arr/FlattenKeysTest.php @@ -8,7 +8,7 @@ * * @author Andrey Helldar * - * @copyright 2024 Andrey Helldar + * @copyright 2025 Andrey Helldar * * @license MIT * @@ -155,4 +155,23 @@ public function testNested() $this->assertEquals($expected, Arr::flattenKeys($array)); } + + public function testMixedKeyTypes() + { + $array = [ + 404 => 'Foo', + '500' => 'Bar', + 'baz' => 'Baz', + 'qwe' => ['rty' => 'Qwerty'], + ]; + + $expected = [ + '404' => 'Foo', + '500' => 'Bar', + 'baz' => 'Baz', + 'qwe.rty' => 'Qwerty', + ]; + + $this->assertEquals($expected, Arr::flattenKeys($array)); + } }