ArrayObjectの引数にArrayIeratorを渡せる。

ArrayObjectを色々と掘り下げられている記事ですが、

[php]
class OddArrayIterator extends ArrayIterator{
 public function next(){
  if( parent::valid() ){
   parent::next();
  }
  if( parent::valid() == false ){
   return;
  }
  return parent::next();
 }
}
$array = array( "a", "b", "c" );
$array = new ArrayObject( $array , 0 , "OddArrayIterator" );
foreach( $array as $value ){
 print( $value );
}
?>
[/php]

$array = new ArrayObject( $array , 0 , “OddArrayIterator” );

こういうコトが出来るのを知らなかったです。
SPLのリファレンスにもちゃんと載ってますね。
勉強になります。

関連する記事:

Powered by

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">