Ben bir navigasyon menüsü oluşturmak için çalışıyorum. Böyle bir yapıya sahip bir dizi alıyorum:
[
[
Title = A
Sub items = [
Title = B
Sub items = [
Title = C
]
]
],
[
Title = A
Sub items = [
Title = B
Sub items = [
Title = D
]
]
],
]
Onu almak ve bu gibi görünmesi gerekir:
[
Title = A
Sub items = [
Title = B
Sub items = [
Title = C,
Title = D
]
]
]
Benim giriş ve aşağıda benim istenen çıktı listeledik. Ben bu benim saç yırtılma ediyorum. Ben özyineleme kullanmaya çalışıyor, ama her yerde sonsuz döngü içine koşu ile bazı sorunlar vardı. Bu mücadele için iyi bir yol üzerinde herhangi bir yardım bu kadar mutluluk duyacağız.
Girdi:
Array
(
[0] => Array
(
[title] => Dashboard
[path] => dashboard/
)
[1] => Array
(
[title] => Settings
[path] => settings/
[subItems] => Array
(
[0] => Array
(
[title] => Instances
[path] => settings/instances/
[subItems] => Array
(
[0] => Array
(
[title] => Add an Instance
[path] => settings/instances/add-an-instance/
)
)
)
[1] => Array
(
[title] => Modules
[path] => settings/modules/
)
[2] => Array
(
[title] => Administrator
[path] => settings/administrator/
[subItems] => Array
(
[0] => Array
(
[title] => Change Password
[path] => settings/administrator/change-password/
)
)
)
)
)
[2] => Array
(
[title] => Settings
[subItems] => Array
(
[0] => Array
(
[title] => Routes
[path] => modules/routes/settings/routes/
)
)
)
[3] => Array
(
[title] => Settings
[subItems] => Array
(
[0] => Array
(
[title] => Cookies
[path] => modules/cookies/settings/cookies/
)
)
)
[4] => Array
(
[title] => Settings
[subItems] => Array
(
[0] => Array
(
[title] => Sessions
[path] => modules/sessions/settings/sessions/
)
)
)
[5] => Array
(
[title] => Settings
[subItems] => Array
(
[0] => Array
(
[title] => Databases
[path] => modules/databases/settings/databases/
[subItems] => Array
(
[0] => Array
(
[title] => Add a Database
[path] => modules/databases/settings/databases/add-a-database/
)
)
)
)
)
[6] => Array
(
[title] => Settings
[subItems] => Array
(
[0] => Array
(
[title] => Models
[path] => modules/models/settings/models/
)
)
)
[7] => Array
(
[title] => Settings
[subItems] => Array
(
[0] => Array
(
[title] => Users and Accounts
[path] => modules/users-and-accounts/settings/users-and-accounts/
)
)
)
[8] => Array
(
[title] => Users and Accounts
[subItems] => Array
(
[0] => Array
(
[title] => Users
[path] => modules/users-and-accounts/users/
[subItems] => Array
(
[0] => Array
(
[title] => Add a User
[path] => modules/users-and-accounts/users/add-a-user/
)
)
)
[1] => Array
(
[title] => Accounts
[path] => modules/users-and-accounts/accounts/
[subItems] => Array
(
[0] => Array
(
[title] => Add an Account
[path] => modules/users-and-accounts/accounts/add-an-account/
)
[1] => Array
(
[title] => Account Types
[path] => modules/users-and-accounts/accounts/account-types/
[subItems] => Array
(
[0] => Array
(
[title] => Add an Account Type
[path] => modules/users-and-accounts/accounts/account-types/add-an-account-type/
)
)
)
)
)
)
)
)
Çıktı:
Array
(
[0] => Array
(
[title] => Dashboard
[path] => dashboard/
)
[1] => Array
(
[title] => Settings
[path] => settings/
[subItems] => Array
(
[0] => Array
(
[title] => Instances
[path] => settings/instances/
[subItems] => Array
(
[0] => Array
(
[title] => Add an Instance
[path] => settings/instances/add-an-instance/
)
)
)
[1] => Array
(
[title] => Modules
[path] => settings/modules/
)
[2] => Array
(
[title] => Administrator
[path] => settings/administrator/
[subItems] => Array
(
[0] => Array
(
[title] => Change Password
[path] => settings/administrator/change-password/
)
)
)
[3] => Array
(
[title] => Routes
[path] => modules/routes/settings/routes/
)
[4] => Array
(
[title] => Cookies
[path] => modules/cookies/settings/cookies/
)
[5] => Array
(
[title] => Sessions
[path] => modules/sessions/settings/sessions/
)
[6] => Array
(
[title] => Databases
[path] => modules/databases/settings/databases/
[subItems] => Array
(
[0] => Array
(
[title] => Add a Database
[path] => modules/databases/settings/databases/add-a-database/
)
)
)
[7] => Array
(
[title] => Models
[path] => modules/models/settings/models/
)
[8] => Array
(
[title] => Users and Accounts
[path] => modules/users-and-accounts/settings/users-and-accounts/
)
)
)
[2] => Array
(
[title] => Users and Accounts
[subItems] => Array
(
[0] => Array
(
[title] => Users
[path] => modules/users-and-accounts/users/
[subItems] => Array
(
[0] => Array
(
[title] => Add a User
[path] => modules/users-and-accounts/users/add-a-user/
)
)
)
[1] => Array
(
[title] => Accounts
[path] => modules/users-and-accounts/accounts/
[subItems] => Array
(
[0] => Array
(
[title] => Add an Account
[path] => modules/users-and-accounts/accounts/add-an-account/
)
[1] => Array
(
[title] => Account Types
[path] => modules/users-and-accounts/accounts/account-types/
[subItems] => Array
(
[0] => Array
(
[title] => Add an Account Type
[path] => modules/users-and-accounts/accounts/account-types/add-an-account-type/
)
)
)
)
)
)
)
)