我有以下结构
[
{
"category_id" : 1,
"parent_category" : null
} ,
{
"category_id" : 2,
"parent_category" : 1
},
{
"category_id" : 3,
"parent_category" : 1
},
{
"category_id" : 4,
"parent_category" : 2
},
,
{
"category_id" : 5,
"parent_category" : null
},
,
{
"category_id" : 6,
"parent_category" : 5
}
]
Run Code Online (Sandbox Code Playgroud)
所以我有父子关系,我想用以下结构对其进行排序
[
{
"parent_category":[ "array of all children that follow this main parent category" ]
},
{},
{}
]
Run Code Online (Sandbox Code Playgroud)
我见过很多解决方案,但都是关于树结构输出的
谢谢