PHP valid() Funzione
Esempio
Controlla se l'elemento corrente è valido dopo una chiamata a rewind() e 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());
?>
Definizione e utilizzo
La funzione valid() controlla se l'elemento corrente è valido dopo una chiamata a rewind() o next() .
Sintassi
SimpleXMLIterator::valid()
Dettagli tecnici
Valore di ritorno: | TRUE se l'elemento è valido. FALSO altrimenti |
---|---|
Versione PHP: | 5.0+ |
Altri esempi
Esempio
Controlla se l'elemento corrente è valido dopo una chiamata a rewind() e 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());
?>
❮ Riferimento PHP SimpleXML