我有一个与此类似的 JSON 文件:
{
"Pages":{
"/":{
"Name": "Home",
"Page": "index.php"
},
"/_admin":{
"Name": "Admin",
"Page": "_admin/index.php",
"Template": "admin",
"MobileTemplate": "admin-mobile",
"Pages":{
"/settings":{
"Name": "Settings",
"Page": "_admin/settings/index.php",
"Config": "_admin/settings/config.php",
"Pages":{
"/user":{
"Name": "Users",
"Page": "_admin/settings/user.php",
"Config": "_admin/settings/config.php",
"CatchAll": true
}
}
}
}
},
"/tasdf":{
"Name": "fs",
"Page": "index.php"
}
}
}
我试图循环遍历这个数组(我已经使用 JSON 解码将其转换为 PHP),并且对于每个“页面”块,我想添加额外的数据。
例如,工作应该如下所示:
Array Loop Starts
Finds "Pages"
-Goes through "/"
-No "Pages" - continue
- Goees through "/_admin"
-Finds "Pages"
-Goes through "/settings"
-Finds "Pages"
-Goes Through "/user"
-No Pages Continue
- Goes through "/tasdf"
- No "Pages" - continue
End Loop
每次它经过一个部分时,我希望它与另一个数组合并。
我正在努力编写代码,以确保每次找到“页面”一词作为关键时它都会继续循环。我已经尝试了很多次,但不断废弃我的代码。
任何对此的帮助都会很棒!