I have this simple setup:
$array1 = array(0 => array(0 => array('amount' => '49')));
$array2 = array(0 => array(0 => array('amount' => '149')));
$mergetest = array_merge_recursive($array1, $array2);
This outputs:
array(2) {
[0]=>
array(1) {
[0]=>
array(1) {
["amount"]=>
string(2) "49"
}
}
[1]=>
array(1) {
[0]=>
array(1) {
["amount"]=>
string(3) "149"
}
}
}
It should merge in such way, that the output should be like this instead:
array(1) {
[0]=>
array(2) {
[0]=>
array(1) {
["amount"]=>
string(2) "49"
}
[1]=>
array(1) {
["amount"]=>
string(3) "149"
}
}
}
Since array index 0 already exists, and so does the array inside it - so it should match by child array instead of parent and in that way add the next child array to it.
Can this be done in a clean way without building a custom function that loops through and checks?
UPDATE
A solution, that also works with:
$array1 = array(0 => array(0 => array('amount' => '49')));
$array2 = array(1243 => array(0 => array('amount' => '49'), 1 => array('amount' => '449')));
Where the output is expected to be in separate parent arrays (0 and 1243), just like the first above output.
array_merge_recursiveto fuse the rows$array1 = array(0 => array('amount' => '49'))); $array2 = array(0 => array('amount' => '149'))); $innermerge = array_merge_recursive($array1, $array2); $mergetest = array(0 => $innermerge);