In PHP, SimpleXMLElement::next() moves the iterator forward to the next child element.
It is one of the iterator methods of SimpleXMLElement, together with rewind(), valid(), current(), and key(). You call next() at the end of each round in a manual loop. In normal code, foreach does this for you, so it is the preferred way to go through children.
Syntax
Call SimpleXMLElement::next() with the values you need. Start with this line.
PHP
$xml->next();
Call
What it does
$xml->next()
Moves the iterator to the next child element.
$xml->rewind()
Moves the iterator back to the first child.
$xml->valid()
Checks whether the iterator still points to a child.
next() returns nothing, so there is no value to check. After the last child, the next call to next() leaves the iterator past the end, and valid() becomes false. Use valid() in your loop condition.
Library declarations
PHP
SimpleXMLElement::next(): void
Parameters
Parameter
Description
—
This function takes no parameters.
Return Value
Return Value
Description
void
Nothing is returned. Use valid() afterwards to see whether there is a child to read.
PHP Examples
Example 1 — Step Through the Children
Move forward one child at a time and read each one. After the last child, valid() becomes false.