downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

ArrayIterator::offsetExists> <ArrayIterator::natsort
[edit] Last updated: Fri, 10 Feb 2012

view this page in

ArrayIterator::next

(PHP 5 >= 5.0.0)

ArrayIterator::next次のエントリに移動する

説明

public void ArrayIterator::next ( void )

この関数は次のエントリにイテレータを移動します。

パラメータ

この関数にはパラメータはありません。

返り値

値を返しません。

例1 ArrayIterator::next() の例

<?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 ArrayIterator::next
onelsonsenna at gmail dot com 06-Oct-2011 08: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. :)

 
show source | credits | stats | sitemap | contact | advertising | mirror sites