There are two arrays

First array

array 0 => array (size=4) 'bonus' => string '5.625' (length=5) 'date' => string '2016-01' (length=7) 'year' => string '2016' (length=4) 'month' => string '1' (length=1) 1 => array (size=4) 'bonus' => string '2.5' (length=3) 'date' => string '2016-02' (length=7) 'year' => string '2016' (length=4) 'month' => string '2' (length=1) 2 => array (size=4) 'bonus' => string '2.5' (length=3) 'date' => string '2016-08' (length=7) 'year' => string '2016' (length=4) 'month' => string '8' (length=1) 3 => array (size=4) 'bonus' => string '10.625' (length=6) 'date' => string '2016-08' (length=7) 'year' => string '2016' (length=4) 'month' => null 4 => array (size=4) 'bonus' => string '22.125' (length=6) 'date' => string '2016-08' (length=7) 'year' => null 'month' => null 

Second array

  array 0 => array (size=4) 'amount' => string '5' (length=1) 'date' => string '2016-07' (length=7) 'year' => string '2016' (length=4) 'month' => string '7' (length=1) 1 => array (size=4) 'amount' => string '6' (length=1) 'date' => string '2016-08' (length=7) 'year' => string '2016' (length=4) 'month' => string '8' (length=1) 2 => array (size=4) 'amount' => string '21' (length=2) 'date' => string '2016-08' (length=7) 'year' => string '2016' (length=4) 'month' => null 3 => array (size=4) 'amount' => string '21' (length=2) 'date' => string '2016-08' (length=7) 'year' => null 'month' => null 

It is necessary to combine arrays, what would happen as follows

  array 0 => array (size=4) 'amount' => string '0' (length=1) 'bonus' => string '5.625' (length=5) 'date' => string '2016-01' (length=7) 'year' => string '2016' (length=4) 'month' => string '1' (length=1) 1 => array (size=4) 'amount' => string '0' (length=1) 'bonus' => string '2.5' (length=3) 'date' => string '2016-02' (length=7) 'year' => string '2016' (length=4) 'month' => string '2' (length=1) 2 => array (size=4) 'amount' => string '5' (length=1) 'bonus' => string '0' (length=3) 'date' => string '2016-07' (length=7) 'year' => string '2016' (length=4) 'month' => string '7' (length=1) 3 => array (size=4) 'amount' => string '6' (length=1) 'bonus' => string '2.5' (length=3) 'date' => string '2016-08' (length=7) 'year' => string '2016' (length=4) 'month' => string '8' (length=1) 4 => array (size=4) 'amount' => string '21' (length=1) 'bonus' => string '10.625' (length=6) 'date' => string '2016-08' (length=7) 'year' => string '2016' (length=4) 'month' => null 5 => array (size=4) 'amount' => string '21' (length=1) 'bonus' => string '22.125' (length=6) 'date' => string '2016-08' (length=7) 'year' => null 'month' => null 

Array sizes are constantly different. I have already broken my head, I can’t understand how to unite them in this way.

Closed due to the fact that the participants are off topic Alexey Shimansky , user207618, aleksandr barakin , pavel , user194374 13 Aug '16 at 6:24 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - Alexey Shimansky, aleksandr barakin, pavel, Community Spirit
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • And what is the merging criterion based on? and if the data of other fields are different, but the join criterion is the same, then what to do? - Alexey Shimansky
  • You write that you have a join criterion date field, but as a result you have 3 identical arrays with the same field ¯ \ _ (ツ) _ / ¯ - Firepro
  • I vote for closing this question as not relevant, because SO is not freelancing. - user207618
  • And here freelance? Where did you see that I ask what they would have done for me? - jemxx

2 answers 2

if you need to merge both arrays into one you need to use the php function array_merge Here is the documentation - array_merge

  • array_merge doesn't fit, it doesn't merge properly - jemxx
  • @jemxx what exactly is wrong? - user193361
  • array_replace_recursive probably - Ninazu

You need the array_map function. In the callback function, merge both nested arrays into one. Read more here: http://php.net/manual/ru/function.array-map.php