My question is a little different from similar posts, in a sense that I don't have any other array to merge with.
I want to merge arrays with in multi-dimensional array.
So that it's not a multi dimensional any more.
Here is the array I have:
Array
(
[2013-12-01::2015-07-29] => Array
(
[TotalMonths] => 1
[0] => 2015-07-01
)
[2015-11-01::2016-03-30] => Array
(
[TotalMonths] => 5
[0] => 2015-11-01
[1] => 2015-12-01
[2] => 2016-01-01
[3] => 2016-02-01
[4] => 2016-03-01
)
[2016-04-01::2017-11-30] => Array
(
[TotalMonths] => 3
[0] => 2016-04-01
[1] => 2016-05-01
[2] => 2016-06-01
)
)
What I am trying is merging all arrays with in. But the index (TotalMonths) is common so only for that it should sum values like (1+5+3) = 8 which will be reflected in new merged array.
I have tried this example also, but I am not sure how I am getting same values.
This is what I have tried so far:
print_r($collidingMonths);
$outPutArray = array();
foreach($collidingMonths as $innerArray) {
$outPutArray[key($innerArray)] = current($innerArray);
}
print_r($outPutArray);
But I am getting a result that I don't want:
Array
(
[TotalMonths] => 3
)
$outPutArray[key($innerArray)] = current($innerArray);why you are usingcurrent?