Yes, but ...
Traversable: "Abstract base interface that cannot be implemented alone. Instead it must be implemented by either IteratorAggregate or Iterator."
So You have to implement IteratorAggregate or Iterator because You can not implement Traversable.
iterator_count
(PHP 5 >= 5.1.3)
iterator_count — イテレータにある要素をカウントする
説明
警告
この関数は、 現在のところ詳細な情報はありません。引数のリストのみが 記述されています。
イテレータにある要素をカウントします。
パラメータ
- iterator
-
カウントしたいイテレータ。
返り値
iterator の要素数を返します。
iterator_count
Micha Mech
09-May-2008 01:38
09-May-2008 01:38
Ard
31-Aug-2006 01:39
31-Aug-2006 01:39
Note that you that the iterator parameter doesn't need to be of type Aggregate. As the spl documentation on http://www.php.net/~helly/php/ext/spl/ defines it in the following way:
iterator_count (Traversable $it).
So you can count the number of files in a given directory quite easily:
<?php iterator_count(new DirectoryIterator('path/to/dir/')); ?>
