Category hierarchy from array(cat id => parent id)
i am trying to create a multidimensional array hierarchy from a simple array which contains pairs of category ids and parent ids. The categories can be a parent and a subcategory at the same time. The base categories have a parent of 0 (=no parent). For example: # cat_id => parent_id $initialArray = array( 1 => 0, 2 => 1, 3 => 2, 4 => 0, 5 => 4, 6 => 0 ); From this, i'd like to get an array that represents a structure like this: 1 2 3 4 5 6 I will not know the contents of $initialArray beforehand. I tried to look at other similar questions but i couldn't find an answer. Please help! Well it