PHP | AppendIterator next()函数
AppendIterator::next()函数是PHP中的一个内置函数,用于将元素移动到下一个元素。
句法:
void AppendIterator::next( void )
参数:此函数不接受任何参数。
返回值:此函数不返回任何值。
下面的程序说明了PHP中的 AppendIterator::next()函数:
方案一:
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"
方案二:
"Geeks",
"b" => "for",
"c" => "Geeks"
)
);
$arr2 = new ArrayIterator(
array(
"x" => "Computer",
"y" => "Science",
"z" => "Portal"
)
);
// Create a new AppendIterator
$itr = new AppendIterator;
$itr->append($arr1);
$itr->append($arr2);
$itr->rewind();
while ($itr->valid()) {
echo "ArrayIterator Key: " . $itr->key() .
" ArrayIterator Value: " . $itr->current() . "\n";
$itr->next();
}
?>
输出:
ArrayIterator Key: a ArrayIterator Value: Geeks
ArrayIterator Key: b ArrayIterator Value: for
ArrayIterator Key: c ArrayIterator Value: Geeks
ArrayIterator Key: x ArrayIterator Value: Computer
ArrayIterator Key: y ArrayIterator Value: Science
ArrayIterator Key: z ArrayIterator Value: Portal
参考: https://www. PHP.net/manual/en/appenditerator.next。 PHP