📜  PHP | AppendIterator current()函数

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

PHP | AppendIterator current()函数

AppendIterator::current()函数是PHP中的一个内置函数,用于获取当前值。

句法:

mixed AppendIterator::current( void )

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

返回值:如果当前值有效,则此函数返回当前值,否则返回 NULL。

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

方案一:

append($arr1);
  
// Display the current element of iterator
var_dump($itr->current());
  
// Use AppendIterator::next() function to
// move into next element
$itr->next();
  
// Display the current element of iterator
var_dump($itr->current());
  
?>
输出:
string(1) "G"
string(1) "e"

方案二:

append($arr1);
$itr->append($arr2);
  
foreach ($itr as $key => $val) {
    var_dump($itr->current());
}
  
?>
输出:
string(5) "Geeks"
string(3) "for"
string(5) "Geeks"
string(8) "Computer"
string(7) "Science"
string(6) "Portal"

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