dd

CStackIterator


system.collections
继承 class CStackIterator
实现 Iterator, Traversable
源自 1.0
版本 $Id: CStackIterator.php 2799 2011-01-01 19:31:13Z qiang.xue $
源码
CStackIterator为CStack实现一个迭代器。

它允许CStack返回一个新的迭代器来遍历栈中的项目。

公共方法

方法 描述 定义在
__construct() 构造方法 CStackIterator
current() 返回数组当前项目。 CStackIterator
key() 返回数组当前项目的键名。 CStackIterator
next() 移动当前索引到下一个项目的位置。 CStackIterator
rewind() 重置当前数组索引位置。 CStackIterator
valid() 返回值说明当前位置是否存在一个项目。 CStackIterator

方法详细

__construct() 方法
public void __construct(array &$data)
$data array 要遍历的数据
public function __construct(&$data)
{
    
$this->_d=&$data;
    
$this->_i=0;
    
$this->_c=count($this->_d);
}

构造方法

current() 方法
public mixed current()
{return} mixed 返回数组当前项目。
public function current()
{
    return 
$this->_d[$this->_i];
}

返回数组当前项目。 此方法为接口Iterator强制要求实现。

key() 方法
public integer key()
{return} integer 返回数组当前项目的键名。
public function key()
{
    return 
$this->_i;
}

返回数组当前项目的键名。 此方法为接口Iterator强制要求实现。

next() 方法
public void next()
public function next()
{
    
$this->_i++;
}

移动当前索引到下一个项目的位置。 此方法为接口Iterator强制要求实现。

rewind() 方法
public void rewind()
public function rewind()
{
    
$this->_i=0;
}

重置当前数组索引位置。 此方法为接口Iterator强制要求实现。

valid() 方法
public boolean valid()
{return} boolean
public function valid()
{
    return 
$this->_i<$this->_c;
}

返回值说明当前位置是否存在一个项目。 此方法为接口Iterator强制要求实现。