iterator_to_array

Supported Versions: PHP 5 >= 5.1.0, PHP 7, PHP 8
Copy the iterator into an array
<?php iterator_to_array(Traversable|array $iterator, bool $preserve_keys = true): array
<?php     public function setMultiple($values, $ttl = null): bool

    {

        return $this->putMany(is_array($values) ? $values : iterator_to_array($values), $ttl);

    }
<?php             return $this->source;

        }



        return iterator_to_array($this->getIterator());

    }
<?php             $items instanceof WeakMap => throw new InvalidArgumentException('Collections can not be created using instances of WeakMap.'),

            $items instanceof Enumerable => $items->all(),

            $items instanceof Arrayable => $items->toArray(),

            $items instanceof Traversable => iterator_to_array($items),

            $items instanceof Jsonable => json_decode($items->toJson(), true),

            $items instanceof JsonSerializable => (array) $items->jsonSerialize(),

            $items instanceof UnitEnum => [$items],
<?php         $this->give(function ($container) use ($tag) {

            $taggedServices = $container->tagged($tag);



            return is_array($taggedServices) ? $taggedServices : iterator_to_array($taggedServices);

        });

    }
<?php     public function files($directory, $hidden = false)

    {

        return iterator_to_array(

            Finder::create()->files()->ignoreDotFiles(! $hidden)->in($directory)->depth(0)->sortByName(),

            false

        );

    }
<?php     public function allFiles($directory, $hidden = false)

    {

        return iterator_to_array(

            Finder::create()->files()->ignoreDotFiles(! $hidden)->in($directory)->sortByName(),

            false

        );

    }
<?php         }



        if ($other instanceof Traversable) {

            return iterator_to_array($other);

        }



        return (array) $other;
<?php             is_object($this->value) && method_exists($this->value, 'toString') => $this->value->toString(),

            $this->value instanceof \Illuminate\Testing\TestResponse => $this->value->getContent(), // @phpstan-ignore-line

            is_array($this->value) => json_encode($this->value, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT),

            $this->value instanceof Traversable => json_encode(iterator_to_array($this->value), JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT),

            $this->value instanceof JsonSerializable => json_encode($this->value->jsonSerialize(), JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT),

            is_object($this->value) && method_exists($this->value, 'toArray') => json_encode($this->value->toArray(), JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT),

            default => InvalidExpectationValue::expected('array|object|string'),
<?php                 $preserveKeysForArrayIterator = $datasets[$index] instanceof Generator

                    && is_string($datasets[$index]->key());



                $datasets[$index] = iterator_to_array($datasets[$index], $preserveKeysForArrayIterator);

            }



            foreach ($datasets[$index] as $key => $values) {
<?php             ['foo', 1],

            ['bar', 2],

            ['baz', 3],

        ], iterator_to_array($this->connection->iterateNumeric($this->query)));

    }



    public function testIterateAssociative(): void
<?php                 'a' => 'baz',

                'b' => 3,

            ],

        ], iterator_to_array($this->connection->iterateAssociative($this->query)));

    }



    public function testIterateKeyValue(): void
<?php             'foo' => 1,

            'bar' => 2,

            'baz' => 3,

        ], iterator_to_array($this->connection->iterateKeyValue($this->query)));

    }



    public function testIterateKeyValueOneColumn(): void
<?php             ->getDummySelectSQL();



        $this->expectException(NoKeyValue::class);

        iterator_to_array($this->connection->iterateKeyValue($sql));

    }



    public function testIterateAssociativeIndexed(): void
<?php             'foo' => ['b' => 1],

            'bar' => ['b' => 2],

            'baz' => ['b' => 3],

        ], iterator_to_array($this->connection->iterateAssociativeIndexed($this->query)));

    }



    public function testIterateColumn(): void
<?php             'foo',

            'bar',

            'baz',

        ], iterator_to_array($this->connection->iterateColumn($this->query)));

    }

}