dgifford/iterator-trait
最新稳定版本:v2.0
Composer 安装命令:
composer require dgifford/iterator-trait
包简介
Trait providing methods implementing the Iterator interface.
README 文档
README
Provides methods for implementing the iterator interface allowing objects to be iterated with a foreach loop.
The trait adds a private property $container to hold the items that are iterated and a private property $position which hold the current position in $container.
Classes must implement the iterator interface.
class Foo implements \Iterator
{
Use IteratorTrait;
public function add( mixed $item ): void
{
$this->container[] = $item;
}
}
$this->foo = new Foo;
$this->foo->add( 'zero' );
$this->foo->add( 'one' );
$this->foo->add( 'two' );
foreach( $this->foo as $key => $value )
{
echo "$key => $value";
}
// 0 => zero
// 1 => one
// 2 => two
统计信息
- 总下载量: 5.08k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0
- 更新时间: 2016-09-16