flat

Build a tree from a flat array in PHP

家住魔仙堡 提交于 2019-11-26 02:19:51
问题 I\'ve looked around the internet and haven\'t quite found what I\'m looking for. I have a flat array with each element containing an \'id\' and a \'parent_id\'. Each element will only have ONE parent, but may have multiple children. If the parent_id = 0, it is considered a root level item. I\'m trying to get my flat array into a tree. The other samples I have found only only copy the element to the parent, but the original still exists. EDIT Each element of the starting array is read from a