YaLinqo\Enumerable::toList PHP Method

toList() public method

Syntax: toList ()

The toList method forces immediate query evaluation and returns an array that contains the query results.

The toList method does not traverse into elements of the sequence, only the sequence itself is converted. That is, if elements of the sequence are {@link Traversable} or arrays containing Traversable values, they will remain as is. To traverse deeply, you can use {@link toListDeep} method.

Keys from the sequence are discarded. To preserve keys and lose values with the same keys, you can use {@link toArray} method. To preserve all values and keys, you can use {@link toLookup} method.

public toList ( ) : array
return array An array that contains the elements from the input sequence.
    public function toList()
    {
        /** @var $it \Iterator|\ArrayIterator */
        $it = $this->getIterator();
        if ($it instanceof \ArrayIterator) {
            return array_values($it->getArrayCopy());
        }
        $array = [];
        foreach ($it as $v) {
            $array[] = $v;
        }
        return $array;
    }