我有一個關於嵌套數組的問題;我搜索谷歌和計算器,但無法找到一個適合我的需求的解決方案: -/從平面數組中使用兒童創建一個嵌套數組
我有以下陣列:
Array
(
[0] => Array
(
[name] => Europe
[children] => Array
(
[0] => West
[1] => East
[2] => South
[3] => North
[4] => Zimbabwe
)
)
[1] => Array
(
[name] => West
[children] => Array
(
[0] => Germany
[1] => France
[2] => Switzerland
[3] => Netherlands
[4] => Belgium
[5] => Luxembourg
[6] => United Kingdom
[7] => Ireland
)
)
[2] => Array
(
[name] => Germany
[children] =>
)
[3] => Array
(
[name] => France
[children] =>
)
)
我想改變它有它嵌套的,即:
Array
(
[0] => Array
(
[name] => Europe
[children] => Array
(
[0] => Array
(
[name] => West
[children] => Array
(
[0]=> Array
(
[name] => Germany
)
[1]=> Array
(
[name] => France
)
)
)
[2] => Array
(
[name] => East
[children] => Array
(
[0]=> Array
(
[name] => Poland
)
[1]=> Array
(
[name] => Austria
)
)
)
)
)
)
你有什麼想法嗎?
在此先感謝!
[你有什麼嘗試?](http://whathaveyoutried.com) – 2013-02-19 14:55:37
你可以在循環內部使用循環,直到你到達你需要修改數組的地方。 – Aborted 2013-02-19 15:05:00
你好晶圓廠,其實我還沒有嘗試過任何東西。說實話,我不知道如何開始......這是一個遞歸函數嗎? – laloune 2013-02-19 15:05:40