PHP 8.5.8 Released!

ArrayIterator::next

(PHP 5, PHP 7, PHP 8)

ArrayIterator::nextMove to next entry

说明

public function ArrayIterator::next(): void

Moves the iterator to the next entry.

参数

此函数没有参数。

返回值

没有返回值。

示例

示例 #1 ArrayIterator::next() example

<?php
$arrayobject = new ArrayObject();
$arrayobject[] = 'zero';
$arrayobject[] = 'one';
$iterator = $arrayobject->getIterator();
while($iterator->valid()) {
 echo $iterator->key() . ' => ' . $iterator->current() . "\n";
 $iterator->next();
}
?>

以上示例会输出:

0 => zero
1 => one

发现了问题?

了解如何改进此页面提交拉取请求报告一个错误
+添加备注

用户贡献的备注 1 note

up
1
onelsonsenna at gmail dot com
14 years ago
If you use exchangeArray method of ArrayObject and then next method of ArrayIterator like this:
<?php
 
 $fruits = array("apple", "grape", "lemon");
 $colors = array("blue", "yellow", "green");
 $arrayObject = new ArrayObject($fruits);
 
 $arrayIterator = $arrayObject->getIterator();
 while($arrayIterator->valid()) {
 if ($arrayIterator->current() == "grape") {
 $arrayObject->exchangeArray($colors);
 }
 $arrayIterator->next();
 }
?>

You will receive:
PHP Notice: ArrayIterator::next(): Array was modified outside object and internal position is no longer valid
So be careful with next and prev operations. :)
+添加备注

AltStyle によって変換されたページ (->オリジナル) /