well, after another long day of trying I still haven't cracked this I've got as far as getting Children processed properly but can't figure out what I have to do for getting Siblings into the equation: Also, I realise that the code on the site point forum will only work with 1 parent top node, So Ive changed my array to contain 1 top level element that I call in order to start the process... So far: //haven't included the hasKids() function below - this just compares 2 lines in the array and returns true or false if the following line is indented more than the first (therefore "hasKids") [code] function rebuild_tree($index, $left) { global $inputLines; global $tree_Array; $right = $left+1; while ($inputLines[$index]) { if(hasKids($index)) { $right = rebuild_tree($index+1, $right); } // write the data $tree_Array[] = "$inputLines[$index] lft:$left rgt:$right"; // return the right value of this node + 1 return $right+1; $index++; } } $inputLines = array('All', ' Games', ' Health', ' Alternative Medicine', ' Beauty & Style', ' Dental', ' Oral Hygene', ' Home', 'Other'); rebuild_tree(0, 1); print_r($tree_Array);[/code] If anyone has any pointers I would love to hear them... so close but yet so far!... [img src=\"style_emoticons/[#EMO_DIR#]/huh.gif\" style=\"vertical-align:middle\" emoid=\":huh:\" border=\"0\" alt=\"huh.gif\" /] btw, this is a diagram of the the result I want to achieve: [img src=\"http://i2.sitepoint.com/graphics/sitepoint_numbering.gif\" border=\"0\" alt=\"IPB Image\" /]