PHP 8.3.0 RC 6 available for testing

Iterator::valid

(PHP 5, PHP 7, PHP 8)

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

说明

public Iterator::valid(): bool

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

参数

此函数没有参数。

返回值

返回将被转换为bool 。成功时返回 true, 或者在失败时返回 false

add a note

User Contributed Notes 2 notes

up
12
seva dot lapsha at gmail dot com
14 years ago
If Iterator::valid() returns false, the foreach() loop will be terminated.
up
5
Voitcus at gmail dot com
10 years ago
If your class implements also ArrayAccess interface, you could use as valid() body

function valid(){
return $this->offsetExists($this->position);
}
To Top