downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

IteratorAggregate> <Iterator::rewind
[edit] Last updated: Fri, 25 May 2012

view this page in

Iterator::valid

(PHP 5 >= 5.0.0)

Iterator::valid現在位置が有効かどうかを調べる

説明

abstract public boolean Iterator::valid ( void )

このメソッドは Iterator::rewind() および Iterator::next() の後にコールされ、 現在の位置が有効化どうかを調べます。

パラメータ

この関数にはパラメータはありません。

返り値

返り値は boolean にキャストして評価されます。 成功した場合に TRUE を、失敗した場合に FALSE を返します。



add a note add a note User Contributed Notes Iterator::valid
hyponiq at gmail dot com 26-Sep-2011 10:12
Take consideration when utilizing this method and using the returned value of isset([value]). The value of isset([value]) will be false for null values.

I ran into this problem when checking isset([value]) against array elements whose value was null.

Example:
<?php
$array
= array(null, 1, 2, 3);
$isSet = isset($array[0]);
var_dump($isSet); // output: boolean(false)

class AClass {
    public
$array = (null, 1, 2, 3);
    function
valid() {
        return isset(
$this->array[0]);
    }
}

$class = new AClass;
var_dump($class->valid()); // output: boolean(false)
?>
seva dot lapsha at gmail dot com 01-Aug-2009 12:19
If Iterator::valid() returns false, the foreach() loop will be terminated.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites