本文整理汇总了PHP中Illuminate\Support\Collection::splice方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::splice方法的具体用法?PHP Collection::splice怎么用?PHP Collection::splice使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Collection
的用法示例。
在下文中一共展示了Collection::splice方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: paginateCollection
/**
* 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()]);
}
示例2: testSplice
public function testSplice()
{
$data = new Collection(['foo', 'baz']);
$data->splice(1);
$this->assertEquals(['foo'], $data->all());
$data = new Collection(['foo', 'baz']);
$data->splice(1, 0, 'bar');
$this->assertEquals(['foo', 'bar', 'baz'], $data->all());
$data = new Collection(['foo', 'baz']);
$data->splice(1, 1);
$this->assertEquals(['foo'], $data->all());
$data = new Collection(['foo', 'baz']);
$cut = $data->splice(1, 1, 'bar');
$this->assertEquals(['foo', 'bar'], $data->all());
$this->assertEquals(['baz'], $cut->all());
}
示例3: limpiarUltimoPedido
public function limpiarUltimoPedido()
{
$this->lista->splice(0, 1);
\Cache::put($this->keyCola, $this->lista, 1440);
}
示例4: spliceContent
/**
* Splice a portion of the underlying content.
*
* @param int $offset
* @param int|null $length
* @param mixed $replacement
* @return $this
*/
protected function spliceContent($offset, $length = null, $replacement = [])
{
$replacement = $this->prepareContentsForInsertion($replacement);
$this->html_contents->splice($offset, $length, $replacement->toArray());
return $this;
}
示例5: summarizeTopBrowsers
protected function summarizeTopBrowsers(Collection $topBrowsers, int $maxResults) : Collection
{
return $topBrowsers->take($maxResults - 1)->push(['browser' => 'Others', 'sessions' => $topBrowsers->splice($maxResults - 1)->sum('sessions')]);
}