合併兩個陣列的方法
P粉548512637
2023-08-31 09:47:28
<p>我正在嘗試合併兩個具有相同鍵的相似數組</p>
<pre class="brush:php;toolbar:false;">Array
(
[0] => 4064628
[1] => 4064953
[2] => 4064922
[3] => 4064870
[4] => 4064789
[5] => 4064631
[6] => 4065044
[7] => 4064942
[8] => 4064938
[9] => 4064936
)
Array
(
[0] => 165020
[1] => 165026
[2] => 165025
[3] => 165023
[4] => 165024
[5] => 165021
[6] => 165027
[7] => 165043
[8] => 165042
[9] => 165045
)</pre>
<p>但當我使用<em>array_merge</em>或<em>array_merge_recursive</em>時,輸出結果相同:</p>
<pre class="brush:php;toolbar:false;">Array
(
[0] => 4064628
[1] => 4064953
[2] => 4064922
[3] => 4064870
[4] => 4064789
[5] => 4064631
[6] => 4065044
[7] => 4064942
[8] => 4064938
[9] => 4064936
[10] => 165020
[11] => 165026
[12] => 165025
[13] => 165023
[14] => 165024
[15] => 165021
[16] => 165027
[17] => 165043
[18] => 165042
[19] => 165045
)</pre>
<p>但我想要這樣的結果:</p>
<pre class="brush:php;toolbar:false;">Array
(
[0] => Array
(
[0] => 4064628
[1] => 165020
)
[1] => Array
(
[0] => 4064935
[1] => 165026
)
[2] => Array
(
[0] => 4064922
[1] => 165025
)
.......</pre>
<p>有人可以幫忙合併這兩個陣列嗎?
這看起來很簡單,但有些東西我不明白,我不知道是什麼</p>