MYSQL 返回一个数组,如下所示。我正在使用 column: 'id_parent' 来自引用表以创建层次结构。因此,“id”为 2 的条目可以是任何“id_parent”为 2 的条目的父项,依此类推。
Array
(
[1] => Array
(
[id] => 2
[name] => About
[id_parent] => NULL
)
[2] => Array
(
[id] => 4
[name] => About Child
[id_parent] => 2
)
[3] => Array
(
[id] => 5
[name] => About Child's Child
[id_parent] => 4
)
)
如何将孩子嵌套到其父数组中的数组中
Array
(
[1] => Array
(
[id] => 2
[name] => About
[id_parent] =>
[children] => Array
(
[id] => 4
[name] => About Child
[id_parent] => 2
[children] => Array
(
[id] => 5
[name] => About Child's Child
[id_parent] => 4
)
)
)
)