我有2個數組。是否有可能創建輸出數組並添加鍵/值從第一個到第二個?我的數組是這樣的:數組搜索和PHP中的組合
第一:
Array
(
[0] => Array
(
[id] => 11
[expire] => undefined
)
[1] => Array
(
[id] => 12
[expire] => undefined
)
[2] => Array
(
[id] => 6
[expire] => 8
)
[3] => Array
(
[id] => 10
[expire] => 4
)
)
第二:
Array
(
[0] => Array
(
[id] => 6
[realname] => to_es.gif
[extension] => gif
[filesize] => 57885
)
[1] => Array
(
[id] => 10
[realname] => to_joomla_2_customer_view.gif
[extension] => gif
[filesize] => 77182
)
[2] => Array
(
[id] => 11
[realname] => to_nl.gif
[extension] => gif
[filesize] => 10990
)
[3] => Array
(
[id] => 12
[realname] => to_PL_1.gif
[extension] => gif
[filesize] => 52826
)
)
我應得的輸出數組:
Array
(
[0] => Array
(
[id] => 6
[realname] => to_es.gif
[extension] => gif
[filesize] => 57885
[expire] => 8
)
[1] => Array
(
[id] => 10
[realname] => to_joomla_2_customer_view.gif
[extension] => gif
[filesize] => 77182
[expire] => 4
)
[2] => Array
(
[id] => 11
[realname] => to_nl.gif
[extension] => gif
[filesize] => 10990
[expire] => undefined
)
[3] => Array
(
[id] => 12
[realname] => to_PL_1.gif
[extension] => gif
[filesize] => 52826
[expire] => undefined
)
)
這裏'foreach'沒有錯;你嘗試過什麼嗎? – Passerby
數組元素的順序是否起作用?在第一個數組中,索引爲[0]的數組的ID爲11.在第二個數組中,第一個數組的第一個數組的ID爲6.那麼你希望如何合併它?你想通過數組索引還是通過id來合併它? – thpl
你好,是應該被id合併。不是索引。 – user889349