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= newSimpleXMLIterator(     '<organization>         <name>zambiatek</name>         <address>Noida India</address>         <email>abc@zambiatek.com</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) "zambiatek"
}
Program 2:
| <?php  Â// Create new SimpleXMLIterator object $xmlIt= newSimpleXMLIterator(     '<organization>         <name>zambiatek</name>         <address>Noida India</address>         <email>abc@zambiatek.com</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
 
				 
					


