我有以下数组。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
位于About
之下,其id为2
,服务parentId为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
或array_map
和foreach
做到这一点。
我只是想知道是否有任何function
连接数组索引,如SQL JOIN没有foreach loop
?
在我的数组中:id = parentId
2条答案
按热度按时间2uluyalo1#
试试这个图书馆
https://github.com/erdalceylan/array-join
资料
用途
输出
iih3973s2#
数组数组,就像在图像中一样。
我个人会用两个表来做,然后使用一个来引用另一个基于密钥。