我有以下数组。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
数组结果。你会看到Services
is 在About
that has id is 2
and 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_walk
orarray_map
轻松做到这一点foreach
。
我只是想知道有没有function
像 SQL JOIN 这样的连接数组索引foreach loop
?
所以在我的数组中:id = parentId