Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Helpers/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* @author Andrey Helldar <[email protected]>
*
* @copyright 2024 Andrey Helldar
* @copyright 2025 Andrey Helldar
*
* @license MIT
*
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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;
}
Expand Down
21 changes: 20 additions & 1 deletion tests/Unit/Helpers/Arr/FlattenKeysTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* @author Andrey Helldar <[email protected]>
*
* @copyright 2024 Andrey Helldar
* @copyright 2025 Andrey Helldar
*
* @license MIT
*
Expand Down Expand Up @@ -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));
}
}