If Iterator::valid() returns false, the foreach() loop will be terminated.
(PHP 5 >= 5.0.0)
Iterator::valid — بررسی صحت موقعیت فعلی
این متد پس از Iterator::rewind() فراخوانی خواهد شد و Iterator::next() برای بررسی صحت موقعیت فعلی است.
This function has no parameters.
مقدار بازگشتی به boolean تبدیل خواهد شد و ارزیابی میشود. Returns TRUE on success or FALSE on failure.
If Iterator::valid() returns false, the foreach() loop will be terminated.
If your class implements also ArrayAccess interface, you could use as valid() body
function valid(){
return $this->offsetExists($this->position);
}