在php中用树枝构建树

时间:2017-05-15 18:14:55

标签: php sorting multidimensional-array parent-child recursive-datastructures

我有$ categories变量返回以下JSON数据。我想在这个变量中用Php构建一个Tree->分支。有什么想法吗?

+公共
- Electonics
.....-计算机
........ + iPad-Tablets
...... +灯光 ..... +家庭申请
+运动

{
"categories": [
    {
        "ID": 0,
        "Name": "Public",
        "Parent": 0,
        "created": null,
        "modified": "2017-03-13T15:16:58+00:00"
    },
    {
        "ID": 4,
        "Name": "Electronics",
        "Parent": 0,
        "created": "2017-03-13T15:18:21+00:00",
        "modified": "2017-03-13T15:18:21+00:00"
    },
    {
        "ID": 5,
        "Name": "Computer",
        "Parent": 4,
        "created": "2017-03-13T15:18:34+00:00",
        "modified": "2017-03-13T15:18:34+00:00"
    },
    {
        "ID": 12,
        "Name": "iPad-Tablets",
        "Parent": 5,
        "created": "2017-05-15T13:55:38+00:00",
        "modified": "2017-05-15T13:55:38+00:00"
    }
]
}

1 个答案:

答案 0 :(得分:0)

此解决方案适用于我的问题。谢谢@DanMiller

INSERT INTO [dbo].[RD_OUTPUT]
VALUES
('2017-04-04 18:00:00.000', 0, 0, 0, 0, 0, 0, 0, 0, 0),
('2017-04-04 19:00:00.000', 6.18733333333333, 6.158, 6.227, 5.82833333333333, 5.796, 5.874, 65.12, 61.52, 68.52),
('2017-04-04 20:00:00.000', 6.07925, 6.04, 6.128, 5.7345, 5.698, 5.776, 75.72, 72.68, 77.44),
('2017-04-04 21:00:00.000', 6.109, 6.021, 6.168, 5.80575, 5.688, 5.884, 72.2, 68.32, 79.56),
('2017-04-04 22:00:00.000', 6.175, 6.119, 6.236, 5.86675, 5.766, 5.972, 66.48, 59.68, 70.72);