Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building a recursive delete function (in php)

Tags:

php

recursion

Here's the deal. I've got a "tree" or a "subtree" that I want to navigate and delete every element in. Each "node" may contain links to other nodes below it (no problem) OR may contain links OUTSIDE that particular "tree"/"subtree". How can I build a function that only deletes "within" the specified tree?

like image 935
Alex Avatar asked Jun 24 '10 10:06

Alex


1 Answers

This is the same recursive delete that you're used to. You just have to keep your links separated - one list for in-tree links, one for out-of-tree links. Alternately, you can have a flag that keeps track of the in-tree/out-of-tree state for each link - but you're going to have to distinguish when you make the link.

like image 74
Curtis Avatar answered Oct 05 '22 23:10

Curtis