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

search for in the

ArrayIterator::current> <Iterators
Last updated: Fri, 09 Jan 2009

view this page in

ArrayIterator クラス

導入

このイテレータは、配列やオブジェクトを反復処理する際に 値やキーをリセットしたり修正したりすることができます。

同じ配列を何度も反復処理したい場合は、 ArrayObject のインスタンスとそれを参照する ArrayIterator のインスタンスを作成し、 foreach を使用するか getIterator() メソッドを手動でコールします。

クラス概要

ArrayIterator
ArrayIterator implements Iterator , Traversable , ArrayAccess , SeekableIterator , Countable {
/* メソッド */
mixed ArrayIterator::current ( void )
mixed ArrayIterator::key ( void )
void ArrayIterator::next ( void )
void ArrayIterator::rewind ( void )
void ArrayIterator::seek ( int $position )
bool ArrayIterator::valid ( void )
}

目次



add a note add a note User Contributed Notes
ArrayIterator
Venelin Vulkov
11-Nov-2008 03:44
Another fine Iterator from php . You can use it especially when you have to iterate over objects

<?php
$fruits
= array(
   
"apple" => "yummy",
   
"orange" => "ah ya, nice",
   
"grape" => "wow, I love it!",
   
"plum" => "nah, not me"
);
$obj = new ArrayObject( $fruits );
$it = $obj->getIterator();

// How many items are we iterating over?

echo "Iterating over: " . $obj->count() . " values\n";

// Iterate over the values in the ArrayObject:
while( $it->valid() )
{
    echo
$it->key() . "=" . $it->current() . "\n";
   
$it->next();
}

// The good thing here is that it can be iterated with foreach loop

foreach ($it as $key=>$val)
echo
$key.":".$val."\n";

/* Outputs something like */

Iterating over: 4 values
apple
=yummy
orange
=ah ya, nice
grape
=wow, I love it!
plum=nah, not me

?>

Regards.

ArrayIterator::current> <Iterators
Last updated: Fri, 09 Jan 2009
 
 
show source | credits | sitemap | contact | advertising | mirror sites