Originally posted by cotterman99
does PHP have any built-in Queue?
No, but it has an array and functions that perform queue and stack operations on it (see array_pop, array_push, array_shift, and array_unshift).
Is this a binary tree? Your array elements could include a pair of elements that point to its descendants. Start with the root, look up its descendants. Once you've got them, stick them on the end of the array and set ['leftchild'] and ['rightchild'] to the array index they were stuck into. Go on to the next element in the array (the first one after the root would be one of those you stuck in while dealing with the root). Repeat the process.
Continue until you come to the end of the array.
Now you've got a tree you can walk by following children.
If it's not a binary tree, then instead of ['leftchild'] and ['rightchild'] elements, there'd be a single ['children'] element, which would be an array of indices.
That's just my first idea. My first ideas aren't necessarily the best (or even particularly good). I'd have to work on the problem myself before I could be confident about whatever I suggest.