The principle is to load the root nodes sequentially first, and then traverse each array to see if there is an array with this root node as the parent node. If so, load it into the drop-down box, and then recurse to see if there is one. The array with this node as the parent node, if there is one, is loaded into the drop-down box, and so on...
The code is as follows: