PHP 7.2.0 Release Candidate 4 Released

Iterator::valid

(PHP 5 >= 5.0.0, PHP 7)

Iterator::valid检查当前位置是否有效

说明

abstract public boolean Iterator::valid ( void )

此方法在 Iterator::rewind()Iterator::next() 方法之后被调用以此用来检查当前位置是否有效。

参数

此函数没有参数。

返回值

返回将被转换为布尔型。成功时返回 TRUE, 或者在失败时返回 FALSE

add a note add a note

User Contributed Notes 2 notes

up
5
Voitcus at gmail dot com
4 years ago
If your class implements also ArrayAccess interface, you could use as valid() body

function valid(){   
   return $this->offsetExists($this->position);
}
up
5
seva dot lapsha at gmail dot com
8 years ago
If Iterator::valid() returns false, the foreach() loop will be terminated.
To Top