Skip to content

Commit

Permalink
Merge pull request #295 from TheDragonCode/6.x
Browse files Browse the repository at this point in the history
Fixed the error of the method of the `arr method :: fluttenkeys` with mixed values
  • Loading branch information
andrey-helldar authored Feb 17, 2025
2 parents f7d0b09 + 428580d commit 33679b6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
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 <helldar@dragon-code.pro>
*
* @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 <helldar@dragon-code.pro>
*
* @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));
}
}

0 comments on commit 33679b6

Please sign in to comment.