當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Collection::getIterator方法代碼示例

本文整理匯總了PHP中Illuminate\Support\Collection::getIterator方法的典型用法代碼示例。如果您正苦於以下問題:PHP Collection::getIterator方法的具體用法?PHP Collection::getIterator怎麽用?PHP Collection::getIterator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Illuminate\Support\Collection的用法示例。


在下文中一共展示了Collection::getIterator方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: toArray

 /**
  * Get the instance as an array.
  *
  * @return array
  */
 public function toArray()
 {
     if ($this->channels instanceof Collection) {
         // 先拿到第一個子級頻道項,並拿到它的父級頻道ID
         // 開始遍曆整個頻道欄目,但是跳過第一條記錄
         // 當然,每當遇到父級頻道ID與當前頻道ID相同
         // 則該為根級頻道,一次搜索完成
         $first = $this->channels->first();
         $cursor = $first->channel_id;
         $iterator = $this->channels->getIterator();
         while ($iterator->valid() && ($channel = $iterator->current())) {
             echo 'prepare' . PHP_EOL;
             if ($channel->channel_id == $cursor || $channel->flag === 1) {
                 $iterator->next();
                 continue;
             }
             echo 'start' . PHP_EOL;
             var_dump($first->channel_id, $first->channel_parent);
             // 當一次搜索完成時,重新搜索數據集
             if (isset($_parent) && $_parent->channel_id === $_parent->channel_parent) {
                 echo 'rewind' . PHP_EOL;
                 $iterator->rewind();
                 continue;
             }
             if ($channel->channel_id === $first->channel_parent) {
                 $_parent = $channel;
                 echo 'merge' . PHP_EOL;
                 var_dump($_parent->channel_id);
                 $this->{$_parent->channel_type}[$_parent->channel_name] = array_merge($this->{$_parent->channel_type}, ['data' => $first, 'idx' => $cursor, 'to' => $_parent->channel_id]);
                 echo 'to wind' . PHP_EOL;
                 var_dump($this->{$_parent->channel_type});
                 // 因為已經設置過子父級關係,則當前數據項設置為1
                 $cursor = $_parent->channel_id;
                 $first = $_parent;
                 $channel->flag = 1;
             }
             echo 'complete' . PHP_EOL;
             $iterator->next();
         }
     }
     return array_merge(['default' => $this->default], ['mega' => $this->mega]);
 }
開發者ID:AInotamm,項目名稱:Haku.moe,代碼行數:47,代碼來源:Channel.php

示例2: testIterable

 public function testIterable()
 {
     $c = new Collection(['foo']);
     $this->assertInstanceOf('ArrayIterator', $c->getIterator());
     $this->assertEquals(['foo'], $c->getIterator()->getArrayCopy());
 }
開發者ID:sa7bi,項目名稱:euro16,代碼行數:6,代碼來源:SupportCollectionTest.php

示例3: getIterator

 /**
  * Get an iterator for the items.
  *
  * @return \ArrayIterator
  */
 public function getIterator()
 {
     return $this->documents->getIterator();
 }
開發者ID:elodex,項目名稱:elodex,代碼行數:9,代碼來源:SearchResult.php

示例4: getIterator

 public function getIterator()
 {
     return $this->results->getIterator();
 }
開發者ID:h4rrison,項目名稱:PHRETS,代碼行數:4,代碼來源:Results.php

示例5: getIterator

 /**
  * Get an iterator for the items.
  *
  * @return ArrayIterator
  */
 public function getIterator()
 {
     return $this->collection->getIterator();
 }
開發者ID:antennaio,項目名稱:laravel-vo,代碼行數:9,代碼來源:ValueObjectCollection.php


注:本文中的Illuminate\Support\Collection::getIterator方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。