當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。