ArrayIterator::next

(PHP 5 >= 5.0.0, PHP 7)

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

add a note add a note

User Contributed Notes 1 note

up
1
onelsonsenna at gmail dot com
12 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. :)
To Top