📜  PHP | SimpleXMLIterator current()函数

📅  最后修改于: 2022-05-13 01:56:20.998000             🧑  作者: Mango

PHP | SimpleXMLIterator current()函数

SimpleXMLIterator::current()函数是PHP中的一个内置函数,用于将当前元素作为 SimpleXMLIterator 对象或 NULL 返回。

句法:

mixed SimpleXMLIterator::current( void )

参数:此函数不接受任何参数。

返回值:此函数在成功时将当前元素作为 SimpleXMLIterator 对象返回,在失败时返回 NULL。

下面的程序说明了PHP中的 SimpleXMLIterator::current()函数:

方案一:


        GeeksforGeeks
        
Noida India
        abc@geeksforgeeks.org     ' );    // Display the current string var_dump($xmlIt->current());    // Use rewind() function to first element $xmlIt->rewind();    // Display the current string var_dump($xmlIt->current());    ?>
输出:
NULL
object(SimpleXMLIterator)#2 (1) {
  [0]=>
  string(13) "GeeksforGeeks"
}

方案二:


        GeeksforGeeks
        
Noida India
        abc@geeksforgeeks.org     ' );       // 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());    ?>
输出:
object(SimpleXMLIterator)#2 (1) {
  [0]=>
  string(11) "Noida India"
}

参考: https://www. PHP.net/manual/en/simplexmliterator.current。 PHP