Implementation in php of a left-right tree traversal algorithm