本文整理匯總了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]);
}
示例2: testIterable
public function testIterable()
{
$c = new Collection(['foo']);
$this->assertInstanceOf('ArrayIterator', $c->getIterator());
$this->assertEquals(['foo'], $c->getIterator()->getArrayCopy());
}
示例3: getIterator
/**
* Get an iterator for the items.
*
* @return \ArrayIterator
*/
public function getIterator()
{
return $this->documents->getIterator();
}
示例4: getIterator
public function getIterator()
{
return $this->results->getIterator();
}
示例5: getIterator
/**
* Get an iterator for the items.
*
* @return ArrayIterator
*/
public function getIterator()
{
return $this->collection->getIterator();
}