我有以下数组。parentId关键重要!
Array
(
[0] => Array
(
[id] => 1
[name] => Home
[parentId] =>
[children] =>
)
[1] => Array
(
[id] => 2
[name] => About
[parentId] =>
[children] =>
)
[2] => Array
(
[id] => 3
[name] => Services
[parentId] => 2
[children] =>
)
)
下面是我的expected数组结果。你会看到Servicesis 在Aboutthat has id is 2and services parentId is下2
Array
(
[0] => Array
(
[id] => 1
[name] => Home
[parentId] =>
[children] =>
)
[1] => Array
(
[id] => 2
[name] => About
[parentId] =>
[children] => Array
(
[0] => Array
(
[id] => 3
[name] => Services
[parentId] => 2
[children] =>
)
)
)
)
我可以用array_walkorarray_map轻松做到这一点foreach。
我只是想知道有没有function像 SQL JOIN 这样的连接数组索引foreach loop?
所以在我的数组中:id = parentId