可能重复:
将数据库结果转换为数组
嗨,伙计们,你能帮帮我吗?如何从 db 表、php 数组或 JSON 中获取分层 php 结构,但格式如下:
[
{
"attributes":{
"id":"111"
},
"data":"Some node title",
"children":[
{
"attributes":{
"id":"555"
},
"data":"A sub node title here"
}
],
"state":"open"
},
{
"attributes":{
"id":"222"
},
"data":"Other main node",
"children":[
{
"attributes":{
"id":"666"
},
"data":"Another sub node"
}
],
"state":"open"
}
]
我的 SQL 表包含以下字段:ID、PARENT、ORDER、TITLE
你能帮我解决这个问题吗?我要疯了才能得到这个。
提前谢谢了。丹尼尔