如何用json和php生成层次结构?

时间:2016-05-07 08:36:01

标签: php json hierarchy

如何生成jsonphp的层次结构,如下图所示?

enter image description here

1 个答案:

答案 0 :(得分:0)

你可以试试这个

阵列:

$arr = array(
    "X1" => array(
        "X2" => array("X4", "X5"),
        "X3" => array("X6", "X7")
    )
);

JSON编码:

echo $json = json_encode($arr); //{"X1":{"X2":["X4","X5"],"X3":["X6","X7"]}}