我試過這樣做了一段時間,無法繞過它。我有兩個數組。一個陣列包含名爲$sendatas
的傳感器信息,另一個陣列包含將這些傳感器分配到的位置,稱爲$zones
。將值從一個數組移動到另一個PHP
我希望能夠根據傳感器是否分配到區域來創建動態HTML複選框,如果它是然後顯示一個複選框,如果它不是,則顯示一個未選中的複選框。
這是我的陣列的一個示例:
的$sendatas
陣列:
[1] => Array
(
[hwserial] => 00002025
[name] => FG05 Room Temp
[serial] => 5
[chan] => 1
[alarmhigh] => 30
[alarmlow] => 5
[delay] => 10
)
[2] => Array
(
[hwserial] => 00002025 01
[name] => FG05 Kitchen 1 Freezer
[serial] => 5
[chan] => 2
[alarmhigh] => -10
[alarmlow] => -35
[delay] => 10
)
的$zones
陣列:
[0] => Array
(
[serial] => 1
[idGrid] => 50
[name] => All Sensors
)
[1] => Array
(
[serial] => 1
[idGrid] => 52
[name] => Food Area
)
[2] => Array
(
[serial] => 2
[idGrid] => 50
[name] => All Sensors
)
[3] => Array
(
[serial] => 2
[idGrid] => 52
[name] => Food Area
)
[4] => Array
(
[serial] => 3
[idGrid] => 50
[name] => All Sensors
)
[5] => Array
(
[serial] => 3
[idGrid] => 52
[name] => Food Area
)
[6] => Array
(
[serial] => 4
[idGrid] => 50
[name] => All Sensors
)
我的兩個區是不一樣的長度。我希望能夠實現的是通過查找兩個數組匹配的序列鍵來創建一個看起來像這樣的數組。
Array
(
[0] => Array
(
[hwserial] => 00001216
[name] => Fridge Office Thermal
[serial] => 1
[chan] => 1
[alarmhigh] => 8
[alarmlow] => -2
[delay] => 10
[idGrid1] => 50
[idGrid2] => 51
[idGrid3] => 52
[zonename1] => All Sensors
[zonename2] => Office
[zonename3] => Food Area
)
[1] => Array
(
[hwserial] => 00002025
[name] => FG05 Room Temp
[serial] => 5
[chan] => 1
[alarmhigh] => 30
[alarmlow] => 5
[delay] => 10
[idGrid] => 50
[idGrid] => Not Used
[idGrid] => 52
[zonename1] => All Sensors
[zonename2] => Not Used
[zonename3] => Food Area
)
我很確定我可以編寫複選框的代碼,一旦我有這個數組格式正確。我曾嘗試使用一些foreach循環,但只是不斷弄亂它。到目前爲止,我已經嘗試了幾個星期,希望能夠找到我,但還沒有。任何幫助讚賞。
添加您嘗試過的代碼是在提問時建議的。 – 707
我已經嘗試瞭解它,但不能......我們應該知道什麼關鍵區域去哪裏? – Salketer
「串行」的關鍵是我希望用來匹配它們的關鍵。我會嘗試找到我已經試過的代碼 – adamp