PHP | SimpleXMLIterator current() Function
Last Updated :
12 Jul, 2025
Improve
The SimpleXMLIterator::current() function is an inbuilt function in PHP which is used to return the current element as a SimpleXMLIterator object or NULL.
Syntax:
php
php
mixed SimpleXMLIterator::current( void )Parameters: This function does not accepts any parameters. Return Value: This function returns the current element as a SimpleXMLIterator object on success or NULL on failure. Below programs illustrate the SimpleXMLIterator::current() function in PHP: Program 1:
<?php
// Create new SimpleXMLIterator object
$xmlIt = new SimpleXMLIterator(
'<organization>
<name>GeeksforGeeks</name>
<address>Noida India</address>
<email>abc@geeksforgeeks.org</email>
</organization>'
);
// Display the current string
var_dump($xmlIt->current());
// Use rewind() function to first element
$xmlIt->rewind();
// Display the current string
var_dump($xmlIt->current());
?>
<?php
// Create new SimpleXMLIterator object
$xmlIt = new SimpleXMLIterator(
'<organization>
<name>GeeksforGeeks</name>
<address>Noida India</address>
<email>abc@geeksforgeeks.org</email>
</organization>'
);
// Display the current string
var_dump($xmlIt->current());
// Use rewind() function to first element
$xmlIt->rewind();
// Display the current string
var_dump($xmlIt->current());
?>
Output:
Program 2:
NULL object(SimpleXMLIterator)#2 (1) { [0]=> string(13) "GeeksforGeeks" }
<?php
// Create new SimpleXMLIterator object
$xmlIt = new SimpleXMLIterator(
'<organization>
<name>GeeksforGeeks</name>
<address>Noida India</address>
<email>abc@geeksforgeeks.org</email>
</organization>'
);
// Use rewind() function to first element
$xmlIt->rewind();
// Use next() function to get
// the next element
$xmlIt->next();
// Display the current string
var_dump($xmlIt->current());
?>
<?php
// Create new SimpleXMLIterator object
$xmlIt = new SimpleXMLIterator(
'<organization>
<name>GeeksforGeeks</name>
<address>Noida India</address>
<email>abc@geeksforgeeks.org</email>
</organization>'
);
// Use rewind() function to first element
$xmlIt->rewind();
// Use next() function to get
// the next element
$xmlIt->next();
// Display the current string
var_dump($xmlIt->current());
?>
Output:
Reference: https://www.php.net/manual/en/simplexmlelement.current
object(SimpleXMLIterator)#2 (1) { [0]=> string(11) "Noida India" }