我有兩個數組在PHP中,我需要傳遞給一個JS腳本。 PHP的陣列locations
和rooms
如下:合併PHP數組和嵌套關係
的var_dump($位置)
Array ([0] => Array
([id] => 1
[name] => "London" )
[1] => Array
([id] => 2
[name] => "Manchester" )
)
的var_dump($房)
Array ([0] => Array
([id] => 1
[locationId] => "1"
[name] => "Lon Room 1" )
[1] => Array
([id] => 2
[locationId] => "1"
[name] => "Lon Room 2" )
[2] => Array
([id] => 3
[locationId] => "1"
[name] => "Lon Room 3" )
[3] => Array
([id] => 4
[locationId] => "2"
[name] => "Man Room 1" )
[4] => Array
([id] => 5
[locationId] => "2"
[name] => "Man Room 2" )
)
我需要客房陣列合併在到適當位置下的位置數組分組中,以便我能夠將以下語法吐出到一個稱爲DailyPlot Sched的JS插件uler。
{ name: "London", id: "1", children:[
{ name : "Lon Room 1", id : "1" },
{ name : "Lon Room 2", id : "2" },
{ name : "Lon Room 3", id : "3" }
]
},
{ name: "Manchester", id: "2", children:[
{ name : "Man Room 1", id : "1" },
{ name : "Man Room 2", id : "2" }
]
}
我在這裏和那裏學習一些東西我學徒的一部分,但我不夠好,由我自己來包裝我解決這個頭,只是還沒有哈哈抱歉,並感謝您!
'$ locations'中的鍵因打字錯誤而不同,或者它們正確? (身份證+姓名,姓名+年齡) – fusion3k
錯別字對不起!好點,我糾正了它。 – Arbiter
我做了大約20次嘗試 - 沒有任何工作,都非常混亂,沒想到會有幫助,對不起。 – Arbiter