I have 2 arrays - they are identical in structure. similar to

Array ( [1] => Array ( [0] => 123 [1] => 412412 [2] => 21424124 ) ) 

and there are 2 array

 Array( [32] => Array ( [7] => 4124124 [8] => 124124 [9] => 124124 ) 

This is just a small piece of the array, in fact there are about 50 values ​​in 1 and in 2 arrays too. On a tree, they are completely identical - the only difference is that they have different keys. How can I replace the value1 of the array (value2) of the m array in this case without touching the keys? I tried array_merge and array_merge_recursive as the replace didn’t help either, advise who came across this, is there any simple solution for this task?

    1 answer 1

    It is necessary that such an algorithm

     $array1; // исходный массивы $array2; // массив донор foreach($array1 as $_key => $_arr) { $_arr2 = current($array2); next($array2); foreach($_arr as $_subarraykey => $_subarrayval) { $_subarray2val = current($_arr2); next($_arr2); $array1[$_key][$_subarraykey] = $_subarray2val; } } 

    those. the algorithm is simple: it makes it possible to parallelize two arrays using next moving the internal pointer forward, and we get the current value using current .

    example http://sandbox.onlinephpfunctions.com/code/206a2090a42a9cc3f862a1318606f833a12b34c5

    • thanks helped) - DampirSIMPL Xelsing