Re: Recursive Iteration over a collection of objects

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



David Lidstone schreef:
Thanks very much to both of you.

This does the trick! I had (stupidly) tried:

foreach ($c as new RecursiveIteratorIterator($item))

which with hindsight is completely illogical! I also wasn't aware of the constants. Is there a simple tutorial / docs you know of for SPL?

not really, there are these 2:

http://www.php.net/~helly/
http://www.php.net/spl

and tutorials of (na)various quality ... and we have Nathan, who seems to
be well up to speed on SPL (IIRC he's tested and posted quite a bit about/with it)

I have tried numerous google searches but the tutorials I have found assume I already know what I am talking about (big mistake:-) ).

keep cross-referencing the info in different sources until something sticks. :-)

Even the PHP docs are very sparse. A real shame, as the SPL seems fantastic and I would love to use it more widely.

SPL has some very nice features, bare in mind that often the abstraction they
offer is a performance overhead ... but not always, for instance I found that
a 'new FilterIterator(new RecursiveDirectoryIterator())' was faster than using
glob() (well 2 calls to glob()) when the number of files exceeded around 300
(in the given directory structure).

One other thing... is there a mirror for this list? I'm sure SPL must have been covered many times before, but every time I try to search, the server times out.

plenty, where do you think the spammers grep your email addr from?
try http://marc.info/?l=php-general&r=1&w=2

...


/mode/      Operation mode (one of):

    * LEAVES_ONLY only show leaves
    * SELF_FIRST show parents prior to their childs
    * CHILD_FIRST show all children prior to their parent

so, i typically use SELF_FIRST, and then Jochem's example would become,

..
foreach(new RecursiveIteratorIterator($c, RecursiveIteratorIterator::SELF_FIRST) as $item)

good catch, wasn't aware of the mode argument, I've only ever played with
it in terms of directory iteration (where LEAVES_ONLY makes sense in the common
use case)

..

-nathan



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux