How to merge two arrays
P粉548512637
P粉548512637 2023-08-31 09:47:28
0
2
499
<p>I'm trying to merge two similar arrays with the same keys</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>But when I use <em>array_merge</em> or <em>array_merge_recursive</em> the output is the same: </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>But I want a result like this:</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>Can anyone help merge these two arrays? This seems simple but there's something I don't understand and I don't know what it is</p>
P粉548512637
P粉548512637

reply all(2)
P粉908138620
$arr=[];
for ($i=0;$i<count($arr1);$i++){
    array_push($arr, [$arr1[$i], $arr2[$i]]);
}
P粉925239921
$output_arr=[];
foreach ($array1 as $key => $value) {
$output_arr[]=[$value,$array2[$key]];}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!