ArrayIterator
在线手册:中文 英文
PHP手册

ArrayIterator::next

(PHP 5 >= 5.0.0)

ArrayIterator::nextMove to next entry

说明

public void ArrayIterator::next ( void )

The iterator to the next entry.

参数

此函数没有参数。

返回值

没有返回值。

范例

Example #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


ArrayIterator
在线手册:中文 英文
PHP手册
PHP手册 - N: Move to next entry

用户评论:

onelsonsenna at gmail dot com (06-Oct-2011 07:09)

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. :)