Friday, August 29, 2025
HomeLanguagesPHP | SimpleXMLIterator current() Function

PHP | SimpleXMLIterator current() Function

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:

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>neveropen</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:

NULL
object(SimpleXMLIterator)#2 (1) {
  [0]=>
  string(13) "neveropen"
}

Program 2:




<?php
  
// Create new SimpleXMLIterator object
$xmlIt = new SimpleXMLIterator(
    '<organization>
        <name>neveropen</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:

object(SimpleXMLIterator)#2 (1) {
  [0]=>
  string(11) "Noida India"
}

Reference: https://www.php.net/manual/en/simplexmliterator.current.php

RELATED ARTICLES

Most Popular

Dominic
32246 POSTS0 COMMENTS
Milvus
80 POSTS0 COMMENTS
Nango Kala
6615 POSTS0 COMMENTS
Nicole Veronica
11787 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11835 POSTS0 COMMENTS
Shaida Kate Naidoo
6731 POSTS0 COMMENTS
Ted Musemwa
7011 POSTS0 COMMENTS
Thapelo Manthata
6685 POSTS0 COMMENTS
Umr Jansen
6699 POSTS0 COMMENTS