PHP- valid()- Funktion
Beispiel
Prüfen Sie, ob das aktuelle Element nach einem Aufruf von rewind() und next() gültig ist:
<?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());
?>
Definition und Verwendung
Die Funktion valid() prüft, ob das aktuelle Element nach einem Aufruf von rewind() oder next() gültig ist .
Syntax
SimpleXMLIterator::valid()
Technische Details
Rückgabewert: | TRUE, wenn das Element gültig ist. Ansonsten FALSCH |
---|---|
PHP-Version: | 5.0+ |
Mehr Beispiele
Beispiel
Prüfen Sie, ob das aktuelle Element nach einem Aufruf von rewind() und next() gültig ist:
<?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());
?>
❮ PHP-SimpleXML-Referenz