PHP Function Reference

PHP SimpleXMLIterator - current() Method



The PHP SimpleXMLIterator::current() method returns the current element as a SimpleXMLIterator object or null.

Syntax

public SimpleXMLIterator::current()

Parameters

No parameter is required.

Return Value

Returns the current element as a SimpleXMLIterator object or null on failure.

Example:

The example below shows the usage of SimpleXMLIterator::current() method.

<?php
$xml = <<<XML
<mail> 
  <To>John Smith</To>
  <From>Marry G.</From>
  <Subject>Happy Birthday</Subject>
  <body>Happy birthday. Live your life with smiles.</body>
</mail> 
XML;

$xmlIterator  = new SimpleXMLElement($xml);
var_dump($xmlIterator->current());

//rewind to first element
$xmlIterator->rewind(); 

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

The output of the above code will be:

NULL
object(SimpleXMLElement)#2 (1) {
  [0]=>
  string(10) "John Smith"
}

❮ PHP SimpleXML Reference