PHP valid() 函数
实例
调用rewind()和next()后检查当前元素是否有效:
<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Do not forget me this weekend!</body>
</note>
XML;
$xml = new SimpleXMLIterator($note);
// rewind to the first element
$xml->rewind();
// check if valid
var_dump($xml->valid());
// move to the next element
$xml->next();
// check if valid
var_dump($xml->valid());
?>
运行实例 »
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Do not forget me this weekend!</body>
</note>
XML;
$xml = new SimpleXMLIterator($note);
// rewind to the first element
$xml->rewind();
// check if valid
var_dump($xml->valid());
// move to the next element
$xml->next();
// check if valid
var_dump($xml->valid());
?>
定义和用法
valid() 函数在调用 rewind() 或 next() 后检查当前元素是否有效 .
语法
SimpleXMLIterator::valid()
技术细节
返回值: | 如果元素有效,则为 TRUE。 否则为 FALSE |
---|---|
PHP 版本: | 5.0+ |
更多实例
实例
调用rewind()和next()后检查当前元素是否有效:
<?php
$xml = new SimpleXMLIterator('<books><book>Learn PHP</book></books>');
// rewind to the first element
$xml->rewind();
// check if valid
var_dump($xml->valid());
// move to the next element
$xml->next();
// check if valid - will be bool(false) because there is only one element
var_dump($xml->valid());
?>
运行实例 »
$xml = new SimpleXMLIterator('<books><book>Learn PHP</book></books>');
// rewind to the first element
$xml->rewind();
// check if valid
var_dump($xml->valid());
// move to the next element
$xml->next();
// check if valid - will be bool(false) because there is only one element
var_dump($xml->valid());
?>