navarr / iterable-to-array
A method for converting an iterable to an array, no matter what type of iterable
Fund package maintenance!
navarr
Installs: 7 428
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: >=7.4
Requires (Dev)
- infection/infection: ^0.25.3
- jetbrains/phpstorm-attributes: ^1.0
- phpstan/phpstan: ^1
- phpunit/phpunit: ^9.5
- roave/security-advisories: dev-master
- squizlabs/php_codesniffer: ^3.6
README
A simple utility class that handles the boilerplate of converting an iterable into an array.
The goal of this utility is to be an in-place replacement for iterator_to_array whenever one must handle an iterable.
Installation
composer require navarr/iterable-to-array
Usage
<?php use Navarr\Utils\IterableToArray // ... $array = IterableToArray::convert($iterable); // This replaces: $array = is_array($iterable) ? $iterable : iterator_to_array($iterable);
This also has (what should be unnecessary) forward compatibility for a scenario where an object passes the iterable
type check but is neither an array
nor a \Traversable
.