php8.5
Home/ Manual/ simplexml / simplexmlelement/ SimpleXMLElement::next

SimpleXMLElement::next

PHP function Edit on GitHub ✎

(PHP 8)

Move to next element

Description

SimpleXMLElement::next(): void
Warning

Prior to PHP 8.0, SimpleXMLElement::next was only declared on the subclass SimpleXMLIterator.

This method moves the SimpleXMLElement to the next element.

Parameters Parameters

Return Values

Void

Examples

Move to the next element

php
<?php
$xmlElement = new SimpleXMLElement('<books><book>PHP Basics</book><book>XML basics</book></books>');
$xmlElement->rewind(); // rewind to the first element
$xmlElement->next();

var_dump($xmlElement->current());
?>

The above example will output:

output
object(SimpleXMLElement)#2 (1) {
  [0]=>
  string(10) "XML basics"
}

Source: reference/simplexml/simplexmlelement/next.xml · from the official PHP manual (php/doc-en)