A
A
a1ukard2016-07-25 17:03:19
PHP
a1ukard, 2016-07-25 17:03:19

How to recursively replace value 1 of array value with another one?

I have 2 arrays - they are identical in structure. like
Array
(
[1] => Array
(
[0] => 123
[1] => 412412
[2] => 21424124
)
)
and there is 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 array 1 and array 2.
Tree-wise they are completely identical - the only difference is that they have different keys .
How can I replace the value of the 1st array (value2) with the second array without touching the keys? I tried
array_merge and array_merge_recursive as well as replace didn't help either, can anyone advise me if there is any simple solution for such a task?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Kravchenko, 2016-07-25
@a1ukard

array_combine(array_keys($arr1), array_values($arr2));

now add recursions

A
a1ukard, 2016-07-25
@a1ukard

for some reason, even in the example, it simply returned the 2nd array without changing the keys
, my task is to insert the value c 1 of the array into the value of the 2nd array recursively.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question