PHP SimpleXML函数

PHP SimpleXMLIterator::current() 方法将当前元素作为 SimpleXMLIterator 对象或 null。

语法

public SimpleXMLIterator::current() 

参数

不需要参数。

返回值

将当前元素作为 SimpleXMLIterator 对象返回,或者返回 null

示例:

下面的示例显示了 SimpleXMLIterator::current() 方法的用法。

<?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());
?>

上述代码的输出将是:

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