本文整理汇总了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();
}