Collection::slice PHP Method

slice() public method

Returns a slice of the collection
public slice ( integer $offset = null, integer $limit = null ) : Collection
$offset integer The optional index to start the slice from
$limit integer The optional number of elements to return
return Collection
    public function slice($offset = null, $limit = null)
    {
        if ($offset === null && $limit === null) {
            return $this;
        }
        $collection = clone $this;
        $collection->data = array_slice($collection->data, $offset, $limit);
        return $collection;
    }

Usage Example

 /**
  * {@inheritdoc}
  */
 public function getSlice($offset, $length)
 {
     return $this->collection->slice($offset, $length);
 }
All Usage Examples Of Collection::slice