<p>I have a web system which has a classical parent-children menu saved in a database, with fields id as the PK, and parent_id to pointing to the owning menu. (Yes, I know this doesn't scale very well, but that's another topic). </p>

<p>So for these records (id-parent_id pairs):</p>

<pre><code>0-7 0-4 4-9 4-14 4-16 9-6
</code></pre>

<p>I have this tree:</p>

<pre><code>0
├ 7
└ 4
  ├ 9
  | └ 6     
  ├ 14
  └ 16
</code></pre>

<p>I'm needing to hide a top node, so I have to make a list of all the childrens of that certain node, i.e. for 4, they will be (9, 6, 14, 16). Order doesn't matters.</p>

<p>I'm confused... does this fits into the classical tree problems? or is it a graph one?</p>

<p>How can I compose this structure and solve this problem using php?</p>

This is the perfect chance to use recursion!
Pseudo-code:
```
```
nodeList = {}
enumerateNodes(rootNode, nodeList);

function enumerateNodes(node, nodeList) {
   nodeList += node;
   foreach ( childnode in node.children ) {
       enumerateNodes(childnode, nodeList);
   }
}
```
```
Edit: Didn't notice that your tree is in the adjacent list format. I would probably just build that into an actual tree datastructure before I started working with it. Just loop through all pairs (creating nodes the first time you see them) and linking them. I
think
it should be easy...