当前位置: 首页>>代码示例>>PHP>>正文


PHP Collection::splice方法代码示例

本文整理汇总了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()]);
 }
开发者ID:muhamadsyahril,项目名称:ecommerce-1,代码行数:19,代码来源:EloquentExtensions.php

示例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());
 }
开发者ID:sa7bi,项目名称:euro16,代码行数:16,代码来源:SupportCollectionTest.php

示例3: limpiarUltimoPedido

 public function limpiarUltimoPedido()
 {
     $this->lista->splice(0, 1);
     \Cache::put($this->keyCola, $this->lista, 1440);
 }
开发者ID:jorgeneira,项目名称:unal-tienda-local,代码行数:5,代码来源:ColaPedidos.php

示例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;
 }
开发者ID:fewagency,项目名称:fluent-html,代码行数:14,代码来源:FluentHtmlElement.php

示例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')]);
 }
开发者ID:spatie,项目名称:laravel-analytics,代码行数:4,代码来源:Analytics.php


注:本文中的Illuminate\Support\Collection::splice方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。