YaLinqo\Enumerable::toArray PHP Method

toArray() public method

Syntax: toArray ()

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

The toArray 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 toArrayDeep} method.

Keys from the sequence are preserved. If the source sequence contains multiple values with the same key, the result array will only contain the latter value. To discard keys, you can use {@link toList} method. To preserve all values and keys, you can use {@link toLookup} method.

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