Skip to content

Commit ccff37c

Browse files
committed
Add support for iterables
1 parent 7ca0098 commit ccff37c

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

src/array.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ function (array $buckets, $x) use ($f) {
342342
* Beware: this method uses references, only modify it
343343
* if you know what you're doing.
344344
*/
345-
function array_as_hierarchy(array $array, $separator = '.'): array
345+
function array_as_hierarchy(iterable $array, $separator = '.'): array
346346
{
347347
$hierarchy = [];
348348
foreach ($array as $key => $value) {
@@ -370,15 +370,13 @@ function array_as_hierarchy(array $array, $separator = '.'): array
370370
* $this->assertFalse(is_numeric_array(['field-1' => 1, 'field-2' => 2]));
371371
* $this->assertFalse(is_numeric_array([1, 2, 'field' => 3]));
372372
*/
373-
function is_numeric_array(array $array): bool
373+
function is_numeric_array(iterable $array): bool
374374
{
375-
foreach (array_keys($array) as $key) {
376-
if (!is_int($key)) {
377-
return false;
378-
}
375+
if ($array instanceof \Traversable) {
376+
$array = iterator_to_array($array);
379377
}
380378

381-
return true;
379+
return array_all(array_keys($array), fn ($key) => is_int($key));
382380
}
383381

384382
/**

0 commit comments

Comments
 (0)