Flat PHP Array to Hierarchy Tree

后端 未结 3 1479
天涯浪人
天涯浪人 2020-12-03 02:11

I have an array with the following keys

id   
parent_id
name

A sample array:

array(7) {
  [0]=>
  array(3) {
    [\"id\"         


        
3条回答
  •  我在风中等你
    2020-12-03 02:20

    You can use FlatToTreeConverter class from Gears helper library:

     $row) {
                $indexed[$row[$parentIdKey]][$childNodesField][$id] = &$indexed[$id];
                if (!$row[$parentIdKey]) {
                    $root[$id] = &$indexed[$id];
                }
            }
            return $root;
        }
    }
    

提交回复
热议问题