PHP 8.3.4 Released!

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
9
seva dot lapsha at gmail dot com
14 years ago
If Iterator::valid() returns false, the foreach() loop will be terminated.
up
7
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