Illuminate\Support\Collection::splice PHP Method

splice() public method

Splice a portion of the underlying collection array.
public splice ( integer $offset, integer | null $length = null, mixed $replacement = [] ) : static
$offset integer
$length integer | null
$replacement mixed
return static
    public function splice($offset, $length = null, $replacement = [])
    {
        if (func_num_args() == 1) {
            return new static(array_splice($this->items, $offset));
        }
        return new static(array_splice($this->items, $offset, $length, $replacement));
    }

Usage Example

 /**
  * Paginates a collection. For simple pagination, one can override this function
  *
  * a little help from http://laravelsnippets.com/snippets/custom-data-pagination
  *
  * @param Collection $data
  * @param int $perPage
  * @param Request $request
  * @param null $page
  *
  * @return LengthAwarePaginator
  */
 public function paginateCollection(Collection $data, $perPage, Request $request, $page = null)
 {
     $pg = $request->get('page');
     $page = $page ? (int) $page * 1 : (isset($pg) ? (int) $request->get('page') * 1 : 1);
     $offset = $page * $perPage - $perPage;
     return new LengthAwarePaginator($data->splice($offset, $perPage), $data->count(), $perPage, Paginator::resolveCurrentPage(), ['path' => Paginator::resolveCurrentPath()]);
 }
All Usage Examples Of Illuminate\Support\Collection::splice