|
Posted by Thomas Mlynarczyk on 10/26/05 13:24
Also sprach Henk Verhoeven:
> 1) under each non-unique key, put another array and put all copies in
> that array. To check if a node is already visited, get its key, then
> search sequentially through the array that is under the key to see if
> one of the nodes in there is identical to the currently visited one.
Sounds like a lot of trouble for a recursion check. :-(
> However, you need a way to distinguish copies from references.
Ay, there's the rub.
> you can only do this in php4 by changing the value of one variable
> and see if the other variable changes too.
Actually, I'd have to check more or less *all* variables to see if there's
one that changes accordingly.
> In php 5 you can use === with objects,
Like "===" would mean "is_reference" and "!==" would mean "is_copy"? That's
great news! :-)
> but not with arrays.
I knew there was a catch... :-(
Hm, so it seems there is no real quick & easy solution for this problem. For
the moment, I think I will stick with a workaround: Limiting the maximum
nesting level while going through the data. At least this will prevent
system hangs. Later I can try to improve my script using your suggestions.
Thanks again for your help!
Greetings,
Thomas
Navigation:
[Reply to this message]
|