Skip to content

Commit 428580d

Browse files
Fixed the error of the method of the arr method :: fluttenkeys with mixed values
1 parent 9cd0a79 commit 428580d

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

src/Helpers/Arr.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
* @author Andrey Helldar <helldar@dragon-code.pro>
1010
*
11-
* @copyright 2024 Andrey Helldar
11+
* @copyright 2025 Andrey Helldar
1212
*
1313
* @license MIT
1414
*
@@ -154,7 +154,7 @@ public function sortByKeys(array|ArrayObject $array, array $sorter): array
154154
{
155155
$sorter = array_intersect($sorter, array_keys($array));
156156

157-
return array_merge(array_flip($sorter), $array);
157+
return $this->merge(array_flip($sorter), $array);
158158
}
159159

160160
/**
@@ -542,7 +542,7 @@ public function flattenKeys(mixed $array, string $delimiter = '.', ?string $pref
542542
if (is_array($value)) {
543543
$values = $this->flattenKeys($value, $delimiter, $new_key);
544544

545-
$result = array_merge($result, $values);
545+
$result = $this->merge($result, $values);
546546

547547
continue;
548548
}

tests/Unit/Helpers/Arr/FlattenKeysTest.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
* @author Andrey Helldar <helldar@dragon-code.pro>
1010
*
11-
* @copyright 2024 Andrey Helldar
11+
* @copyright 2025 Andrey Helldar
1212
*
1313
* @license MIT
1414
*
@@ -155,4 +155,23 @@ public function testNested()
155155

156156
$this->assertEquals($expected, Arr::flattenKeys($array));
157157
}
158+
159+
public function testMixedKeyTypes()
160+
{
161+
$array = [
162+
404 => 'Foo',
163+
'500' => 'Bar',
164+
'baz' => 'Baz',
165+
'qwe' => ['rty' => 'Qwerty'],
166+
];
167+
168+
$expected = [
169+
'404' => 'Foo',
170+
'500' => 'Bar',
171+
'baz' => 'Baz',
172+
'qwe.rty' => 'Qwerty',
173+
];
174+
175+
$this->assertEquals($expected, Arr::flattenKeys($array));
176+
}
158177
}

0 commit comments

Comments
 (0)