Quick question really:
I've seen in bits of code in the past where the code could call count() on a object that implements Iterator, for custom Iterator classes.
I've written a class that implements Iterator and works fine in a foreach loop, but I was just wondering if there was an extra class I had to extend or function I had to implement in order for count() to work on my class, to return a value I want.
I don't have much experience with Iterators, but this looks like what you're looking for:
The Countable interface
Classes implementing Countable can be used with the count() function.
If you only have to do a count on your Iterator class, you can use the iterator_count() function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With