简体   繁体   中英

How to generate hierarchy with json and php?

How to generate a hierarchy with json and php like the image below?

在此处输入图片说明

You can try this

Array:

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

JSON Encode:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM