Fusonic\Linq\Linq::skip PHP Method

skip() public method

Bypasses a specified number of elements and then returns the remaining elements.
public skip ( integer $count ) : Linq
$count integer The number of elements to skip before returning the remaining elements.
return Linq A Linq object that contains the elements that occur after the specified index.
    public function skip($count)
    {
        // If its an array iterator we must check the arrays bounds are greater than the skip count.
        // This is because the LimitIterator will use the seek() method which will throw an exception if $count > array.bounds.
        $innerIterator = $this->iterator;
        if ($innerIterator instanceof \ArrayIterator) {
            if ($count >= $innerIterator->count()) {
                return new Linq([]);
            }
        }
        if (!$innerIterator instanceof \Iterator) {
            // IteratorIterator wraps $innerIterator because it is Traversable but not an Iterator.
            // (see https://bugs.php.net/bug.php?id=52280)
            $innerIterator = new \IteratorIterator($innerIterator);
        }
        return new Linq(new \LimitIterator($innerIterator, $count, -1));
    }