How to merge two dumery array?

There are two arrays, which are taken from different places.

As an example:

Array
(
 [0] => Array
(
 [id] => 57
 [fullName] => Ivanov Ivan Ivanovich
 [firstName] => Ivan
 [middleName] => Ivanovich
 [lastName] => Ivanov
 [email] => test@test.ru
)

 [1] => Array
(
 [id] => 250
 [fullName] => Sidorov Ivan Ivanovich
 [firstName] => Ivan
 [middleName] => Ivanovich
 [lastName] => Sidorov
 [email] => test1@test.ru
)
 [2] => Array
(
 [id] => 2530
 [fullName] => Ivan Petrov Ivanovich
 [firstName] => Ivan
 [middleName] => Ivanovich
 [lastName] => Petrov
 [email] => test2@test.ru
)
)


Array
(
 [0] => Array
(
 [ids] => 57
 [age] => 50
)

 [1] => Array
(
 [ids] => 250
 [age] => 43
)
 [2] => Array
(
 [ids] => 2530
 [age] => 33
)
)


You need PHP 5.3 to make a new array contain all the data of the second array.

Something like this:
Array
(
 [0] => Array
(
 [id] => 57
 [fullName] => Ivanov Ivan Ivanovich
 [firstName] => Ivan
 [middleName] => Ivanovich
 [lastName] => Ivanov
 [email] => test@test.ru
 [ids] => 57
 [age] => 50
)

 [1] => Array
(
 [id] => 250
 [fullName] => Sidorov Ivan Ivanovich
 [firstName] => Ivan
 [middleName] => Ivanovich
 [lastName] => Sidorov
 [email] => test1@test.ru
 [ids] => 250
 [age] => 43
)
 [2] => Array
(
 [id] => 2530
 [fullName] => Ivan Petrov Ivanovich
 [firstName] => Ivan
 [middleName] => Ivanovich
 [lastName] => Petrov
 [email] => test2@test.ru
 [ids] => 2530
 [age] => 33
)
)


I do not do turns well, etc. I can not understand how to combine them.

[0] => Array
(
 [id] => 57
 [fullName] => Ivanov Ivan Ivanovich
 [firstName] => Ivan
 [middleName] => Ivanovich
 [lastName] => Ivanov
 [email] => test@test.ru 
)
 [1] => Array
(
 [ids] => 57
 [age] => 50 
 )
June 10th 19 at 15:17
2 answers
June 10th 19 at 15:19
Thank you very much, now I will try to understand. And apply. - Joana.Gusikowski commented on June 10th 19 at 15:22
even you can mark the answer - albertha.Medhur commented on June 10th 19 at 15:25
June 10th 19 at 15:21
1. Using foreach collect new arrays in which the keys will have the value of the id or ids for the first and second array respectively.
2. $result_array = array_merge_recursive($new_array1, $new_array2) P. S if in advance it is possible to form arrays with the right keys when retrieving data from the database that would be great.
1. I have tried foreach-what to collect. Failed.
2. array_merge_recursive - also did not work it just adds another key.
The problem is that one array is selected from the database, the second is converted from jsona.

By the way can anyone advise some lessons are not for beginners. But it was mostly just simple stuff apart all of the manuals. - Joana.Gusikowski commented on June 10th 19 at 15:24
I agree, array_merge_recursive is not suitable. Suitable array_replace_recursuve - checked.
By the way during the foreach extra keys can be removed, but it is - cosmetics.
foreach ($array1 as $v){
 $new_array1[$v['id']] = $v;
}

 foreach ($array2 as $v){
 $new_array2[$v['ids']] = $v;
}

 $result_array = array_replace_recursive($new_array1, $new_array2);


The end result is the following:
Array
(
 [57] => Array
(
 [id] => 57
 [fullName] => Ivanov Ivan Ivanovich
 [firstName] => Ivan
 [middleName] => Ivanovich
 [lastName] => Ivanov
 [email] => test@test.ru
 [ids] => 57
 [age] => 50
)

 [58] => Array
(
 [id] => 58
 [fullName] => Ivanov Ivan Ivanovich
 [firstName] => Ivan
 [middleName] => Ivanovich
 [lastName] => Ivanov
 [email] => test@test.ru
 [ids] => 58
 [age] => 50
)

)


P. S about the "by the Way can anyone advise some lessons are not for beginners. But it was mostly just simple stuff apart all of the manuals. " I can say this: the Best lesson is not for beginners is a really hard challenge where you have to think and read the manuals. Gradually, decisions will come faster, and the experience - to grow. - albertha.Medhur commented on June 10th 19 at 15:27

Find more questions by tags PHP