Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Beware</strong> of the examples that just do it recursively. </p> <p>Php can create arrays with references to other places in that array, and can contain objects with likewise recursive referencing, and any purely recursive algorithm could be considered in such a case a <em>DANGEROUSLY</em> naive one, in that it will overflow stack depth recursing, and never terminate. </p> <p>( well, it will terminate when it exceeds stack depth, and at that point your program will fatally terminate, not what I think you want )</p> <p>In past, I have tried serialise -> replacing reference markers with strings -> deserialise for my needs, ( Often debugging backtraces with loads of recursive references in them ) which seems to work OK, you get holes everywhere, but it works for that task. </p> <p>For your task, if you find your array/structure has recursive references cropping up in it, you may want to take a look at the user contributed comments here: <a href="http://php.net/manual/en/language.references.spot.php" rel="noreferrer">http://php.net/manual/en/language.references.spot.php</a></p> <p>and then somehow find a way to count the depth of a recursive path. </p> <p>You may need to get out your CS books on algorhthms and hit up these babies: </p> <ul> <li><a href="http://en.wikipedia.org/wiki/Depth-limited_search" rel="noreferrer">Wiki:Depth-limited-search</a></li> <li><a href="http://en.wikipedia.org/wiki/Depth-first_search" rel="noreferrer">Wiki:Depth-first search</a></li> </ul> <p>( Sorry for being so brief, but delving into graph theory is a bit more than suited for this format ;) ) </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload